Issue with Memory Consumption and OOM Errors When Using docxImage with Base64 Images



  • Hello,

    We are implementing a Word report using the docx recipe and encountered issues when inserting multiple images into the report.

    Issue Description
    To include images, we use the docxImage helper, providing the src as a base64 data URL. In the beforeRender script, images are prefetched to handle authentication properly and then passed to docxImage.

    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 docxImage to 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, axios is responsible for loading images inside the docxImage helper, specifically in this line:
    https://github.com/jsreport/jsreport/blob/master/packages/jsreport-docx/lib/imageUtils.js#L32

    We 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 Authorization header for authenticated requests

    • Adjust httpsAgent settings to support self-signed certificates

    I initially tried setting axios defaults within the report script, but I suspect that docxImage and 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 configuring axios inside docxImage would 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 docxHtml helper - 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 docx recipes task. It can take a month to get to this I guess.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.