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.

Image: Base64 as src is broken

See original GitHub issue

OS: MacOS 10.14

React-pdf version: 1.0.0-alpha.18

Description: Base64 as Image src is broken and throws Couldn't fetch image: <string>. isomorphic-fetch, which used node-fetch under the hood throws Error: only http(s) protocols are supported.

I suspect this commit, that implemented isomorphic-fetch: https://github.com/diegomura/react-pdf/commit/72d0454c0876c24386b7a37b53f39293ef3540d0, as it’s younger than #216, which seems to conclude that this should be working as expected and documented in the docs.

Suggested actions

  • Somehow detect and handle base64 strings as src, as node-fetch simply does not support this. Maybe something like Buffer.from(<string>, 'base64').
  • Properly output node-fetch errors for future debugging, instead of just Couldn't fetch image: <string>.
  • Add a base64 test case in image.test.js.

Alternatively, remove the instructions from the documentation, if this functionality is unwanted.

How to replicate issue including code snippet (if applies): https://runkit.com/embed/uj7thrhoup3u

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
kievmontanacommented, Mar 30, 2020

Hi guys!

Make sure that you insert the Image in the correct way: <Image source={ {uri: 'YOUR IMAGE'} }/>

Next check if your base64 size is not too large. - if the size is ok, it should work.

7reactions
gavin771commented, Dec 13, 2019

same for me. No image is rendered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javasscript: load image with base64 not working
It looks like the base64 encoding for your image is incorrect. This renders a broken image <img src="data:image/png;base64 ...
Read more >
Issue with Lazy Load and base64 - WordPress.org
Image is not being displayed and when inspecting the source code I notice base64 encoding for my image source: src="data:image/gif;base64 ...
Read more >
How to fix broken base64 image using image-webpack and ...
The problem I was experiencing and tyring to document here is, after installing image-webpack and file-loader and using <img src={require('logo.
Read more >
Storing and displaying images with base64 | by Tung Nguyen
Commonly, to display images in HTML or CSS we have to indicate URLs located ... Passes a base64 encoded data directly into “src”...
Read more >
How to Display Base64 Images in HTML - W3docs
The <img> tag has a src attribute and contains the Data URL of the image. A Data URL is composed of two parts,...
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