Forum Moderators: open

Message Too Old, No Replies

Javascript file saving

         

Greven

12:11 am on Apr 12, 2008 (gmt 0)

10+ Year Member



Hello All,

I have a Flex application that exports an image as base64 encoded data(a png), and I want to save it via javascript(as far as I'm aware, there is NO way to save from flash). So, here is the code I have working:


function saveSnapshot(output)
{
var filename = "C:\\test.png";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ts = fso.CreateTextFile(filename);
ts.Write(output);
ts.Close();
}

This will take the base64 string from flex and save it into the file(This will be running from inside an intranet only through IE6/7, so the site is in a safe zone, so the security is not an issue). If I open the file in a text editor(I'm using notepad++), I see the base64 data, and using the built in base64 decoder in notepad++, it will successfully convert it, and display the PNG properly.

However, I want to avoid the notepad++ step as I want other people to be able to use it easily. I have tried javascript base64 decoders(webtoolkits, for example), but it is dreadfully slow(15+mins) and it didn't even work. I found the "ScriptUtils.ByteArray" activex object, which seems great, since I can just give it a base64 string, and it even has a saveas function to directly save to a file location. However, the activex object doesn't seem to work in IE7(can't test with Ie6 yet).


var bytearray = new ActiveXObject("ScriptUtils.ByteArray");
bytearray.Base64 = output;
bytearray.SaveAs(filename);

Does anyone have any suggestions? Either an effiecent way to decode base64 in javascript, or a way to get ScriptUtils.ByteArray to work would be great.

Thanks in advance.

Greven

12:48 am on Apr 12, 2008 (gmt 0)

10+ Year Member



I've discovered that the ScriptUtils is a propoetary library, so that option is out. Anyone know another way to decode base64 quickly?

httpwebwitch

7:20 am on Apr 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm stumped. ActiveX is not in my comfort zone...
I have a feeling this might be easier to pull off if it was done using server technology, rather than using client-side routines and ActiveX

Greven

4:35 pm on Apr 12, 2008 (gmt 0)

10+ Year Member



It would be,yes, but I don't have access to them in my intranet.

bendzi

8:41 pm on Apr 17, 2008 (gmt 0)

10+ Year Member



Hi

i tried this exact method of saving to a file (from an svg document), it seemed to work fine as when i clicked on my "save button" the browser prompted me to allow the activex script run, which i did.

it reported that data had been saved to the file successfuly with no errors, but nothing was actully saved to the file when i checked!

am i doing somethign wrong? any help on this?

cheers