简体   繁体   English

如何使用来自通过Flex URLRequest发送的POST数据的javascript在HTML页面上显示文件?

[英]How to display a file on an HTML page with javascript from POST data sent via a Flex URLRequest?

I'm trying to add "file preview" functionality to my Flex app. 我正在尝试为我的Flex应用添加“文件预览”功能。 I have a LinkButton in Flex that, when clicked, should open the file in a new browser window. 我在Flex中有一个LinkBut​​ton,当点击它时,应该在新的浏览器窗口中打开文件。 I found a helpful actionscript class that properly formats the POST data to pass the file to an HTML page. 我找到了一个有用的actionscript类,它正确地格式化POST数据以将文件传递给HTML页面。 The file POST data is put into a URLRequest, which is sent to the HTML page through a URLLoader. 文件POST数据被放入URLRequest,URLRequest通过URLLoader发送到HTML页面。

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. 我的问题是我对Javascript不是很熟悉,而且我不知道如何告诉HTML页面显示Flex应用程序发送的文件。 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). 我不是要求任何人为我编写代码,我只需要一个好的起点(一个关键字,一个javascript函数来阅读,一些东西)。

I would like to use a combination of HTML and Javascript to take the POST data and open the included file in the browser. 我想使用HTML和Javascript的组合来获取POST数据并在浏览器中打开包含的文件。

Other important information: the file needs to be displayed in IE8 and the files being displayed are mostly image files, PDFs, or Word docs. 其他重要信息:文件需要在IE8中显示,显示的文件主要是图像文件,PDF或Word文档。

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. 我从那里抓取文件并将其作为ByteArray存储在自定义类中。 I then pass the ByteArray to my helper class that formats the POST data request and stores the result in URLRequest.data. 然后我将ByteArray传递给我的助手类,该类格式化POST数据请求并将结果存储在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). 所以我正在寻找一种方法(理想地使用Javascript和HTML)来处理该请求并让浏览器显示文件(或者如果用户没有要显示的正确插件,则显示打开/保存对话框)。

First simple case want to display images or pdf (plugins needed) 第一个简单的案例想要显示图像或pdf(需要插件)

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

If you want something pass data to html page you need to consider following code 如果您想要将数据传递到html页面,则需要考虑以下代码

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. 之后你需要通过Javascript从javascript GET参数值获取路径值然后你可以解析GET参数然后你可以玩DOM元素。

I thought we can't get the POST value from JavaScript alone we need to use server scripts. 我以为我们不能单独从JavaScript获取POST值,我们需要使用服务器脚本。 Post-variables-with-jquery . post-variables-with-jquery

MS Words to open in browser it will help View/Open Word Document . MS Word在浏览器中打开它将有助于查看/打开Word文档 I am not sure about Word Docs. 我不确定Word Docs。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在URLRequest Flex 4 / Air中替换HTML标签 - How to replace HTML tag in URLRequest Flex 4 / Air 如何通过 MVC Controller 中的 WebApi 从 HTML 页面发布数据 - How to POST Data from HTML Page via WebApi in MVC Controller 如何通过 javascript 从 html 页面中的特定 github txt 文件中获取数据 - How to fetch data from a particular github txt file in html page via javascript 如何使用jQuery从HTML页面获取所有数据ID和金额并通过带有数据的Ajax发布 - How to get all data-id and amount from html page using jQuery and post it via ajax with data 重定向到HTML按钮单击上的PHP文件,并通过POST发送一些数据 - Redirect to a PHP file on a HTML button click with some data being sent via POST 如何处理从Javascript发送到Python的POST数据并返回输出? - How to process POST data sent from Javascript to Python and return the output? 如何显示以javascript发送的id为mysql的数据(Adobe Phonegap) - How to display data from mysql with id sent with javascript ( Adobe Phonegap ) 是否可以通过javascript或python(Flask)将文本文件中的数据打印到html页面? - Is it possible to print the data from a text file to a html page via javascript or python(Flask)? 如何显示从vue javascript到html的数据 - How to display data from vue javascript to html 如何遍历 XML 文件并使用 JavaScript 在 HTML 网页中显示数据? - How can I iterate over an XML file and display the data in a HTML web page using JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM