question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Images are not rendered due to CORS issue

See original GitHub issue

Describe the bug I am not being able to load some of the images (specially images with large dimensions). Even this image doesn’t work. https://via.placeholder.com/720x400.png

<Image
       style={styles.image}
        src="https://via.placeholder.com/720x400.png"
      />

To Reproduce Steps to reproduce the behavior including code snippet (if applies):

  1. Go to ‘https://react-pdf.org/repl
  2. Replace the local image with the remote link -> https://via.placeholder.com/720x400.png
  3. Notice that you won’t be able to see image.
  4. However, when you use CORS addons like CORS Everywhere, the image shows up.

You can make use of react-pdf REPL to share the snippet

Expected behavior We should be able see the remote image rendered in PDF.

Desktop (please complete the following information):

  • OS: [MacOS]
  • Browser [chrome, safari, firefox]
  • React-pdf version latest

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
primordiuscommented, May 18, 2020

If you are using AWS S3, make sure your bucket has a proper Cross-origin resource sharing and you are setting the random query string mentioned above https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html#how-do-i-enable-cors Example CORS policy:

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>*</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
 </CORSRule>
</CORSConfiguration>

Document:

<Image
  src={imageSource + '?noCache=' + Math.random().toString()}
/>
1reaction
llmdevcommented, Apr 14, 2020
<Image
  src={ imageUrl }
  source={{
    header: {
       'Access-Control-Allow-Origin': '*'
    }
  }}
/>

maybe that helps

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dealing with image CORS error in Chrome, Chromium and ...
The issue comes from the way that Chromium caches the images. The way that the initial image is cached is - without the...
Read more >
Allowing cross-origin use of images and canvas - HTML
HTML provides a crossorigin attribute for images that, in combination with an appropriate CORS header, allows images defined by the <img> ...
Read more >
Images not loading due to CORS, depending if you v...
Images in reports published to the PowerBI service are no longer rendering if you visit via different URL prefixes; either app.powerbi.com or www.powerbi....
Read more >
Html <img src=...> works but JS Image loading cause CORS ...
I try to found solution my self (JS ES6) but find only-partially. We are able to load img from no-CORS support src into...
Read more >
<img crossorigin=""> » - HTML
Adding appropriate request headers for images is as simple as adding the crossorigin attribute to the <img> element. If your browser supports CORS,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found