Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2012, 02:43 PM   PM User | #1
JasonC
New to the CF scene

 
Join Date: May 2009
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
JasonC is an unknown quantity at this point
How to display a file on an HTML page with javascript from POST data sent from Flex?

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:

Code:
--lljcuqjclcnyicgrmwexayhafmkhiwfx

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



arrows.png

--lljcuqjclcnyicgrmwexayhafmkhiwfx

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

Content-Type: image/png



?PNG

"image information as ByteArray"



--lljcuqjclcnyicgrmwexayhafmkhiwfx

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



Submit Query

--lljcuqjclcnyicgrmwexayhafmkhiwfx--
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).
JasonC is offline   Reply With Quote
Old 12-03-2012, 07:36 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,553
Thanks: 9
Thanked 480 Times in 463 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
spit the data back as a base64 string and concat to build a data url to use as the .src of an iframe.

PHP Code:
 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.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
JasonC (12-03-2012)
Reply

Bookmarks

Tags
actionscript, flex, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:50 AM.


Advertisement
Log in to turn off these ads.