views:

62

answers:

6

I have an image encoded in base64 in a javascript variable : data:image/png;base64, base64 data

[EDIT] I need to save that file to disk without asking to the visitor to do a right click [/EDIT]

Is it possible ? How ?

Thanks in advance

Best regards

+2  A: 

You can't. You can read this post.

Spilarix
+4  A: 

... without asking to the visitor anyhing ... Is it possible?

No, that would have been a security hole. If it was possible, one would be able to write malware to the enduser's disk unaskingly. Your best bet may be a (signed) Java Applet. True, it costs a bit of $$$ to get it signed (so that it doesn't pop security warnings), but it is able to write data to enduser's disk without its permission.

BalusC
+1  A: 

It's not possible.

If it was, browsers would be massively insecure, being able to write random data to your hard disk without user interaction.

jvenema
A: 

I think it's possible with JavaScript if you use ActiveX.

Another possibility is to make the server spit out that file with a different mime type so the browser asks the user to save it.

Júlio Santos
Using ActiveX restricts you however to a single webbrowser type (MSIE) and even then, MSIE in its default setup will scare the enduser with all kinds of security warnings before continuing. ActiveX, no thanks.
BalusC
Of course. But I thought it was still worth mentioning.
Júlio Santos
+1  A: 

with javascript, you can't. the only real possibility i can think of will be a java-applet, but maybe (i don't know how long that image should be saved) you could simply add an img-tag with you png and force caching (but if the user deletes his cache, the image will be gone).

oezi
+1  A: 

As other answers already stated, you cannot do it only with javascript. If you want, you can send the data (using normal HTTP POST) to a PHP script, call header('Content-type: image/png') and output the decoded image data to the page using echo base64_decode($base64data).

This will work just as if user clicked on an image and open it or prompt him to save the file to disk (the normal browser's save file dialog).