Actionscript 3 &引用;错误“2038”:在flex中进行文件上传时
在flex中上载文件时,我发现IOEvent的错误为error#2038 我用谷歌搜索了一下,但我没有找到任何合适的解决方案,可能是如何实现这一点。之前代码工作正常。但现在它显示了这个错误 这在IE中有效,但在其他浏览器中显示错误 有人知道吗 好的,这是AS3代码…请检查一下Actionscript 3 &引用;错误“2038”:在flex中进行文件上传时,actionscript-3,apache-flex,file-upload,Actionscript 3,Apache Flex,File Upload,在flex中上载文件时,我发现IOEvent的错误为error#2038 我用谷歌搜索了一下,但我没有找到任何合适的解决方案,可能是如何实现这一点。之前代码工作正常。但现在它显示了这个错误 这在IE中有效,但在其他浏览器中显示错误 有人知道吗 好的,这是AS3代码…请检查一下 package com.firstplanet.views.actions { import com.adobe.serialization.json.JSON; import com.firstplanet.events
package com.firstplanet.views.actions
{
import com.adobe.serialization.json.JSON;
import com.firstplanet.events.ErrorLogEvent;
import com.firstplanet.events.SaveAdminItemEvent;
import com.firstplanet.model.ModelLocator;
import com.firstplanet.views.modules.admin.winProgress;
import flash.display.DisplayObject;
import flash.events.DataEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.KeyboardEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import flash.net.Responder;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.ui.Keyboard;
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
public class FileUploader
{
public function FileUploader()
{
}
[Bindable]private var theModel:ModelLocator = ModelLocator.getInstance();
private var urlRequest:URLRequest;
private var fileReference:FileReference;
private var fileReferenceList:FileReferenceList;
private var fileList:Array;
private var isLargerFile:Boolean;
private var _winProgress:winProgress;
private var __errorEvt:ErrorLogEvent;
[Bindable] public var photoName:String;
[Bindable] public var theExtension:String;
private var thePhotoTypeID:Number;
[Bindable]public var file_name:String="";
public var theAdminItem:Object = new Object();
public var serverSideScript:String = "assets/php/FileUploader.php";
private var max_file_size:Number;
public var saveDet:Object;
public var theAdminObj:Object;
public var isUpload:Boolean;
public function chooseFiles(fileType:String,fileFormat:String,max_size:Number):void
{
fileReferenceList = new FileReferenceList();
fileReferenceList.addEventListener(Event.SELECT, onSelectFile);
fileReferenceList.addEventListener(Event.CANCEL,onCancel);
var arr:Array = [];
arr.push(new FileFilter(fileType, fileFormat));
fileReferenceList.browse(arr);
max_file_size = max_size;
if(fileType == "All")
{
isUpload = true;
}
}
private function onCancel(event:Event):void{
theModel.tempFlag = false;
}
private function convertBytestoMB(maxFileSize:Number):Number
{
var theMb:Number;
theMb = maxFileSize/1024;
theMb = theMb/1024;
return theMb;
}
public function onSelectFile(event:Event):void
{
var fileReferenceList:FileReferenceList = FileReferenceList(event.target);
fileList = fileReferenceList.fileList;
// get the first file that the user chose
fileReference = FileReference(fileList[0]);
file_name = fileList[0].name;
//newFileLabel.label=fileList[0].name;
//if(fileList[0].size > maxFileSize)
if(fileList[0].size > Number(max_file_size))
{
//var theMB:Number = convertBytestoMB(maxFileSize);
var theMB:Number = convertBytestoMB(max_file_size);
theModel.uploadStatusMessage = "Selected file is around "+Math.round(convertBytestoMB(fileList[0].size))+" MB. Please select a file that must not exceed "+theMB+ " MB. ";
theModel.saveErrorLogs("CertificateUpload",theModel.uploadStatusMessage);
Alert.show(theModel.uploadStatusMessage);
isLargerFile = true;
return;
}
else
{
theModel.uploadStatusMessage = "";
isLargerFile = false;
theModel.saveErrorLogs("CertificateUpload","This is not a large file");
//saveBtn.enabled = true;
}
//previewfileName=fileList[0].name;
if(isUpload)
{
if(theModel.fileManagerVO!=null)
{
uploadFile("../../"+theModel.fileManagerVO.folderPath,null,null);
theModel.saveErrorLogs("CertificateUpload","Upload file path : ../../"+theModel.fileManagerVO.folderPath);
}
}
}
public function uploadFile(path:String,theAdminItem:Object,saveDetObj:Object):void
{
saveDet = saveDetObj;
theAdminObj = theAdminItem;
if(fileList!=null)
{
if(isLargerFile)
{
Alert.show(theModel.uploadStatusMessage);
return;
}
theModel.deleteOldFile = false;
if(theAdminItem!=null)
{
theModel.deleteOldFile = true;
if(theAdminItem.url!=null)
{
theModel.oldFileName = theAdminItem.url;
}
}
_winProgress = winProgress(PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, winProgress, true));
_winProgress.btnCancel.removeEventListener("click", onUploadCanceled);
_winProgress.btnCancel.addEventListener("click", onUploadCanceled);
//_winProgress.title = "Uploading file to " + domain;
if(fileList!=null)
{
_winProgress.txtFile.text = fileList[0].name;
file_name = fileList[0].name;
}
_winProgress.progBar.label = "0%";
PopUpManager.centerPopUp(_winProgress);
// Variables to send along with upload
var sendVars:URLVariables = new URLVariables();
sendVars.action = "upload";
sendVars.path = path;
var request:URLRequest = new URLRequest();
request.data = sendVars;
request.url = serverSideScript;
request.method = URLRequestMethod.POST;
fileReference = new FileReference();
fileReference = FileReference(fileList[0]);
fileReference.addEventListener(Event.OPEN, onUploadOpen);
fileReference.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
fileReference.addEventListener(Event.COMPLETE, onUploadComplete);
fileReference.addEventListener(IOErrorEvent.IO_ERROR, onUploadIoError);
fileReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadSecurityError);
fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadCompleteReturn);
fileReference.upload(request);
}
else
{
//saveItem();
theModel.deleteOldFile = false;
submitData(saveDet,theAdminObj);
}
}
private function onUploadOpen(evt:Event):void
{
_winProgress.uploadProgressMessage.text = "Uploading please wait..."
}
// Get upload progress
private function onUploadProgress(event:ProgressEvent):void
{
var numPerc:Number = Math.round((Number(event.bytesLoaded) / Number(event.bytesTotal)) * 100);
_winProgress.progBar.setProgress(numPerc, 100);
_winProgress.progBar.label = numPerc + "%";
_winProgress.progBar.validateNow();
if (numPerc > 90)
{
_winProgress.btnCancel.enabled = false;
//_winProgress.uploadProgressMessage.text = "Cropping your photo..Please wait..."
}
else
{
_winProgress.uploadProgressMessage.text = "Uploading please wait..."
_winProgress.btnCancel.enabled = true;
}
}
private function onUploadComplete(event:Event):void
{
PopUpManager.removePopUp(_winProgress);
_winProgress.uploadProgressMessage.text = "Please wait..."
theModel.uploadStatusMessage="File have been uploaded.";
theModel.saveErrorLogs("CertificateUpload",theModel.uploadStatusMessage);
if(isUpload)
{
theModel.fileManagerVO.gatewayConnection.call( "data.files.getFiles", new Responder(theModel.fileManagerVO.onFileResult, theModel.fileManagerVO.onFault),theModel.fileManagerVO.folderPath);
}
}
public function onUploadCompleteReturn(evt:DataEvent):void
{
if(evt!=null)
{
if(evt.data!=null)
{
try
{
theModel.saveErrorLogs("CertificateUpload","came to onUploadCompleteReturn");
var rawData:String = evt.data as String;
var manager:Array = JSON.decode(rawData);
if(manager!=null && manager[0]!=null)
{
var tempObj:Object = manager[0] as Object;
var status:Boolean = tempObj.theStatus as Boolean;
if(status)
{
if(tempObj.FileName!=null)
{
photoName = tempObj.FileName as String;
}
if(tempObj.theExtension!=null)
{
theExtension = tempObj.theExtension as String;
}
theModel.uploadStatusMessage="File have been uploaded.";
theModel.isPhotoUploaded = true;
if(!isUpload)
{
submitData(saveDet,theAdminObj);
}
}
else
{
photoName = "";
theModel.uploadStatusMessage="That file was not a recognised type or was unable to be decoded.";
}
}
PopUpManager.removePopUp(_winProgress);
}
catch(e:Error)
{
Alert.show("Error in uploading the file");
}
}
else
{
Alert.show("Error in uploading the file");
}
}
}
private function onUploadIoError(event:IOErrorEvent):void
{
theModel.uploadStatusMessage="IO Error in uploading file.";
PopUpManager.removePopUp(_winProgress);
theModel.saveErrorLogs("CertificateUpload",event.text);
//Alert.show("IO Error in uploading file.", "Error");
}
// Called on upload security error
private function onUploadSecurityError(event:SecurityErrorEvent):void
{
theModel.uploadStatusMessage="Security Error in uploading file.";
theModel.saveErrorLogs("CertificateUpload",theModel.uploadStatusMessage);
//Alert.show("Security Error in uploading file.", "Error");
PopUpManager.removePopUp(_winProgress);
_winProgress == null;
fileReference.cancel();
}
// Called on upload cancel
private function onUploadCanceled(event:Event):void
{
PopUpManager.removePopUp(_winProgress);
theModel.uploadStatusMessage = "You have cancelled the operation";
_winProgress == null;
fileReference.cancel();
//clearUpload();
}
private function submitData(theObj:Object,theAdminItem:Object):void
{
if(photoName!=null)
{
theObj["url"] = photoName;
}
else
{
theObj["url"] = theAdminItem.url;
}
if(theExtension!=null)
{
theObj["type"] = theExtension;
}
else
{
theObj["type"] = theAdminItem.audio_type;
}
theModel.updateCourseDetails(theObj,'image');
}
}
}
错误
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2038"]
嘿,我终于找到了解决办法。如果有人面临类似的问题,请遵循以下基本步骤 这里我面临的问题是文件在IE(所有版本)中上传,但在其他浏览器中不起作用 然后按照以下步骤操作
- --首先尝试调度HTTPStatusEvent
- --检查即将发生的错误。如果URL是有效的,它将不会给出错误,否则它将显示error responseURL=null
- --然后检查服务器端脚本路径(上传文件时使用的内容)
- --在我的例子中,我将文件的完整URL作为路径传递,而不是(assets/../fileuploader.php)
- --然后错误将被解决
看: 我在web.config到1Gb文件中使用下面的代码解决了一个相同的问题
<system.web>
<httpRuntime maxRequestLength="2097152" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
我试着这样做并解决了我的问题 Flex应用程序初始化后,立即调用远程服务器方法来检索服务器会话ID。在Java中,远程方法如下所示:
public String getSessionInfo()
{
return FlexContext.getFlexSession().getId();
}
你能发一些代码吗?否则,就没有什么可处理的了。@JasonMc92我已经编辑并添加了代码。请检查。编译器说错误出现在哪一行?嘿,我已经提到它是一个IOEvent错误。fileReference.addEventListener处的行(IOErrorEvent.IO_ERROR,onUploadIoError);在这个方法中,“event.text”表示错误#2038谢谢。我知道是什么错误,但行号有助于缩小范围。url显示该页面不可用