3

I'm trying to add "file preview" functionality to my Flex app. 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 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. After countless web searches, I decided to ask here. I'm not asking for anyone to write the code for me, I just need a good place to start from (a keyword, a javascript function to read about, something).

I would like to use a combination of HTML and Javascript to take the POST data and open the included file in the browser.

Other important information: the file needs to be displayed in IE8 and the files being displayed are mostly image files, PDFs, or Word docs.

Edit: Here is some info I forgot to mention. The files I want to display are being stored in the database. I'm grabbing the file from there and storing in a custom class as a ByteArray. I then pass the ByteArray to my helper class that formats the POST data request and stores the result in URLRequest.data.

Here's what my request looks like:

--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).

Jason
  • 71
  • 10
  • image preview you can do in flex with file reference.load() and grab the byteArray from the complete event. For the pdfs... this looks like it might help [jspdf](http://snapshotmedia.co.uk/blog/jspdf) – Jason Reeves Nov 28 '12 at 23:02

1 Answers1

0

First simple case want to display images or pdf (plugins needed)

navigateToUrl(new URLRequest("http://localhost/images/hello.png"));

If you want something pass data to html page you need to consider following code

var req:URLRequest = new URLRequest("http://www.localhost/openfile.html");
req.data = "path='http://localhost/images/hello.png'";
req.method = URLRequestMethod.GET;
navigateToURL(req);

After that you need to get the path value from javascript GET Parameter values through Javascript then you can parse GET parameter then you can play with DOM elements.

I thought we can't get the POST value from JavaScript alone we need to use server scripts.Post-variables-with-jquery .

MS Words to open in browser it will help View/Open Word Document. I am not sure about Word Docs.

Community
  • 1
  • 1
Raja Jaganathan
  • 33,099
  • 4
  • 30
  • 33
  • I can't use navigateToUrl because the files I want to display are being stored in the database, and I can't access them through a URL. I'm currently pulling the file out of the database into a custom class that stores the file as a ByteArray. I then pass the ByteArray into my helper class that formats the POST data and I store the results from that into the URLRequest.data. – Jason Nov 30 '12 at 14:47
  • Please see the edit to my original question above. And thanks for the reply. – Jason Nov 30 '12 at 15:04