如何使 Flex 文件上传在 Firefox 和 safari 上工作? [英] How do I make Flex file upload work on firefox and safari?

查看:21
本文介绍了如何使 Flex 文件上传在 Firefox 和 safari 上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 flex 应用程序,可以将文件上传到服务器.服务器需要身份验证才能上传.在 IE 中,上传工作正常.但是在 FF 和 Safari 中,它不会上传.我见过到处都有同样问题的人,但没有答案.现在不要让我失望 stackoverflowers.

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.

基于其他人链接的flash player bug,以及在该页面上的评论中,我决定将会话标识符附加到我的上传 URL 并试一试.真的就是这么简单!

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!

为了让它发挥作用,我首先添加了一个名为 sessionParams 的 flashVar 参数.这允许我将我想要的任何字符串作为我的会话标识符传递给 Flash 播放器,然后它会附加到用于上传的 URL.

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;
}

就我而言,我使用的是启用了 java 会话的 ColdFusion,所以我的 sessionParams 在传递到 Flash 播放器之前设置如下:

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)#" />

不要忘记转义 =、& 等特殊字符(我已经用 urlEncodedFormat 完成了),以便将它们视为sessionParams"参数值的一部分,而不是断点来指示其他参数.您正在当前 URL 中嵌入未来 URL 信息.

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.

然后,在上传代码中使用 sessionParams 值.这是我如何设置我的一个片段:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆