如何让Flex文件上传在Firefox和Safari浏览器上工作? [英] How do I make Flex file upload work on firefox and safari?
问题描述
我有一个flex应用程序,可以将文件上传到服务器。服务器需要认证才能上传。在IE中,上传工作正常。但是在FF和Safari中,它不会上传。我已经看到了所有人都有这个相同的问题,但没有答案。现在不要让我失望。
我在尝试自己找到答案时发现了这个问题。解决的办法很简单。
//设置URLRequest
_uploadURL = new URLRequest;
_uploadURL.url = _url +? + _sessionParams;
_uploadURL.method =GET;
_uploadURL.data = _variables;
_uploadURL.contentType =multipart / form-data;
变量名是不同的(但相似),因为它是可重用类的一部分。 >
希望能帮到你。如果没有,让我知道,我会尽量提供更多的代码或解释来帮助你。
I have a flex app that uploads files to a server. The server requires authentication to be able to upload. In IE the upload works fine. However in FF and Safari, it does not upload. I have seen people all over with this same problem but no answers. Don't fail me now stackoverflowers.
I found this question while trying to find the answer myself. The solution was rather simple.
Based on the flash player bug that others have linked, and the comments on that page, I decided to append session identifiers to my upload URL and give it a shot. It really was that easy!
To make it work, I started by adding a flashVar parameter called sessionParams. This allowed me to pass any string I want in to the flash player as my session identifier, and it will later get appended to the URL used to upload.
//sessionParams - resolves firefox upload bug
public var sessionParams:String = "";
//...
public function initApp():void{
sessionParams = Application.application.parameters.sessionParams;
}
In my case, I'm on ColdFusion with java sessions enabled, so my sessionParams
are setup like the following before being passed into the flash player:
<cfset flashVars = "sessionParams=#urlEncodedFormat('jsessionid=' & session.sessionid)#" />
Don't forget to escape special characters like =,&, etc (which I've done with urlEncodedFormat), so that they are treated as part of the value of the "sessionParams" parameter, and not breakpoints to indicate other parameters. You're embedding future-URL information in the current URL.
Then, use the sessionParams value in your upload code. Here's a snippet of how I set mine up:
// Set Up URLRequest
_uploadURL = new URLRequest;
_uploadURL.url = _url + "?" + _sessionParams;
_uploadURL.method = "GET";
_uploadURL.data = _variables;
_uploadURL.contentType = "multipart/form-data";
The variable names are different (but similar) because this is part of a reusable class.
Hopefully that helps you. If not, let me know and I'll try to provide more code or explanation to help you out.
这篇关于如何让Flex文件上传在Firefox和Safari浏览器上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!