View Full Version : How to display a file on an HTML page with javascript from POST data sent from Flex?

12-03-2012, 03:43 PM
I have a Flex app that I'm trying to add "file preview" functionality to. I have a LinkButton in Flex that, when clicked, should open the file in a new browser window. I found a helpful actionscript class that properly formats the POST data to pass the file to an HTML page. The files I want to preview are being stored in the database, and I'm passing the through the POST data as a ByteArray. The file POST data is put into a URLRequest, which is sent to the HTML page through a URLLoader.

My problem is that I'm not very experienced with Javascript and I don't know how to tell the HTML page to display the file being sent by the Flex app. Any suggestions on how to handle this would be greatly appreciated.

I would like to use a combination of HTML and Javascript to take the POST data and open the included file in the browser. The file needs to be displayed in IE8 and the files being displayed are mostly image files, PDFs, or Word docs.

Here's what my POST request looks like:


Content-Disposition: form-data; name="Filename"



Content-Disposition: form-data; name="Filedata"; filename="arrows.png"

Content-Type: image/png


"image information as ByteArray"


Content-Disposition: form-data; name="Upload"

Submit Query


So I'm looking for a way (using Javascript and HTML ideally) to handle that request and have the browser display the file (or display an open/save dialog if the user doesn't have the proper plugins to display).

rnd me
12-03-2012, 08:36 PM
spit the data back as a base64 string and concat to build a data url to use as the .src of an iframe.

echo "data:" . $mimeType . ";" . $base64fileData ;

dataURLs are supposed to work in IE8, as long as the document isn't too big.
if you want 100% compatibility, you might just have to iframe the server response and give up on JS doing it for you.