微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flex FileReference 在Firefox 浏览器情况下的异常情况

Question: Flex 3.5 或 Flex 4 + pureMVC + BlazeDs + Java 1.6.0_18 + Spring + Hibernate 环境下开发的App,在做上传导入文件时,遇到了浏览器兼容问题。

在IE下,导入完全没问题;但在Firefox 下导入失败。跟踪Service 发现用Firefox 做导入请求时,该请求对象中未携带session信息导致的。查阅了API,没找到有效的解决办法。用IE和Firefox 做导入时,Service端取得的信息如下:

 

firefox导入时

用IE做导入时

 

Solution: 在UI端做上传请求的URL中人为地添加sessionid信息。

var sessionId: String = ApplicationFacade.getInstance().currentUser.sessionId;
     _url = _url.replace("?",";jsessionid=" + sessionId + "?");

Importer.as 类如下:

public class Importer  {         public static function upload(displayObj:displayObject,url:String):void   {    var _url:String = url;      var parentObj:displayObject = displayObj;    var  file:FileReference =new FileReference();    openFile();    var pb:PopupProgressBar = PopUpManager.createPopUp(parentObj,PopupProgressBar,true) as PopupProgressBar;                   file.addEventListener(ProgressEvent.PROGRESS,onProgress);    file.addEventListener(Event.SELECT,onSelect);    file.addEventListener(Event.CANCEL,onCancel);    file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadComplateHandler);        file.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);        function uploadComplateHandler(event : DataEvent) : void    {     PopUpManager.removePopUp(pb);    }        function errorHandler(evt:IOErrorEvent):void    {      PopUpManager.removePopUp(pb);     }        function onCancel(evt:Event):void    {      PopUpManager.removePopUp(pb);     }        function onProgress(e:ProgressEvent):void    {     pb.importProgess(true);              PopUpManager.centerPopUp(pb)    }        function openFile():void    {     file.browse([new FileFilter("File Type(*.csv)","*.csv;")]);    }      function onSelect(e:Event):void    {        proceedWithUpload();    }      function proceedWithUpload():void    {     try     {      var sessionId: String = ApplicationFacade.getInstance().currentUser.sessionId;      _url = _url.replace("?",";jsessionid=" + sessionId + "?");      var request:URLRequest = new URLRequest(_url);                  request.method = URLRequestMethod.POST;                  file.upload(request,"file");     }     catch (error:Error)     {      PopUpManager.removePopUp(pb);      Alert.show("upload Failed");     }    }       }  }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐