0

Suppose I have the entire Base64 string for an image that is generated dynamically. How can I convert something like this:

<img src="data:image/jpeg;base64,/9j/blah blah blah........." />

to

<img src="mypic.jpg" />

Is it even possible to do on the client side without downloading the image to the server? Is there maybe a way to temporarily cache the Base64 image into memory and receive an actual image file?

1
  • 1
    What are you trying to achieve here? Commented Aug 19, 2012 at 8:10

1 Answer 1

6

Is it even possible to do on the client side without downloading the image to the server?

No.

Assuming the page is loaded from the server, then changing the src attribute like that would point it at a URI on that server. The browser would try to load the image from there, so it would have to return the image and not 404.

There is no way to for a website to inject content for an arbitrary URI into the browser cache.

Sign up to request clarification or add additional context in comments.

2 Comments

hmm ok. Reason why I need to do this is because I am using a javascript image editing plugin that only accepts urls in the form of 'path/to/image.jpg'. I am allowing users to choose an image via the HTML5 FileReader API. Which returns a base64 string when the image is displayed on the page. It would have been ideal if I could bypass the file upload entirely for the rest of the script.
@Jakerow: step through the plugin in the debugger until you see why it fails with data URLs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.