React-to-print: External Image links are broken

Created on 18 Mar 2020  路  8Comments  路  Source: gregnb/react-to-print

Description

  • I have an image tag that fetches its image from Google Storage but the image is broken.

Screenshot 2020-03-18 at 15 39 52

Any ideas how to go about this?

Most helpful comment

The issue happens when you don't give DOM enough time to load the image once it has the src set. stackoverflow

A quick hack is to download the image blob then convert it to image URL, in advance. Then use it on the print content.

fetch( 'image-url') ) .then(function(response) { return response.blob(); }) .then(function(blob) { var urlCreator = window.URL; var imageUrl = urlCreator.createObjectURL(blob); setImageLogo(imageUrl); }); }

All 8 comments

Hello. Is it broken in general, or just when using react-to-print? Can you please share a codesandbox example if possible? Thanks

When using react-to-print the external image from GCP storage links dont show up it instead shows just a broken image link.. Will try to reproduce in a codesandbox

Yeah, if you could make a working codesandbox that would be fantastic, thank you

Hey @MatthewHerbst I couldnt replicate it on CodeSandbox so i screen recorded it instead, apologies for the screen size

dad

Here is the image link that was generated https://storage.googleapis.com/elliot-images-us/production/842/lookandfeel/SLxB_FullLogo-02.png

Screen record link for the video - https://recordit.co/TlghI5Dc4K

I don't see you opening the print window in that video? I really can't do much to investigate without a reproducible example unfortunately.

The issue happens when you don't give DOM enough time to load the image once it has the src set. stackoverflow

A quick hack is to download the image blob then convert it to image URL, in advance. Then use it on the print content.

fetch( 'image-url') ) .then(function(response) { return response.blob(); }) .then(function(blob) { var urlCreator = window.URL; var imageUrl = urlCreator.createObjectURL(blob); setImageLogo(imageUrl); }); }

Thanks a lot @p8ul that solved it.. Thanks also @MatthewHerbst for the time

Glad that got figured out, thank you

Was this page helpful?
0 / 5 - 0 ratings