Issue with Memory Consumption and OOM Errors When Using docxImage with Base64 Images
-
Hello,
We are implementing a Word report using the
docxrecipe and encountered issues when inserting multiple images into the report.Issue Description
To include images, we use thedocxImagehelper, providing thesrcas a base64 data URL. In thebeforeRenderscript, images are prefetched to handle authentication properly and then passed todocxImage.However, this approach leads to high memory consumption, often resulting in an Out of Memory (OOM) error when processing larger images or multiple images at once.
At the same time, when images are provided as direct URLs - allowing
docxImageto handle the loading - everything works fine.Reproduction
We have created a minimal example to reproduce the issue: https://playground.jsreport.net/w/anon/CVpIkxye (See README for details).Possible Cause & Suggested Solution
From what I see,axiosis responsible for loading images inside thedocxImagehelper, specifically in this line:
https://github.com/jsreport/jsreport/blob/master/packages/jsreport-docx/lib/imageUtils.js#L32We would like to know if there’s a way to provide custom options to this axios request. In our case, we need to:
-
Set an
Authorizationheader for authenticated requests -
Adjust
httpsAgentsettings to support self-signed certificates
I initially tried setting
axiosdefaults within the report script, but I suspect thatdocxImageand report scripts run in separate contexts, so this approach didn't work.Request for Support
Is there a recommended way to handle this? Any advice on working around the OOM issue or configuringaxiosinsidedocxImagewould be greatly appreciated.Thanks in advance!
-
-
Thank you for the ticket. It makes sense.
I've submited task to backlog to deal with it.
https://github.com/jsreport/jsreport/issues/1216
-
Hi Jan, thanks for creating a ticket for that! I noticed that the same issue is occurring in the
docxHtmlhelper - would you be able to look into improving image loading there as well?Also, do you have an estimated timeframe for when this might be picked up?
-
I noticed that the same issue is occurring in the docxHtml helper
I've updated the task
Also, do you have an estimated timeframe for when this might be picked up?
We have currently long queue with
docxrecipes task. It can take a month to get to this I guess.
-
as part of jsreport
4.9.0we can use a custom loader function to control how images are fetched. this can be used in bothdocxImageanddocxHtml, see the updated docs 1, 2.
-
Thank you, guys! The ability to provide a custom loader function fully meets our needs and resolves the OOM issues we were facing.