“Error #2038” : while file upload in flex

2019-08-25 05:16发布

I figured out an error as Error #2038 for IOEvent while file uploading in flex.

I googled out but i didn't find any proper solution may be how to implement that. The code is working properly before. But now its showing this error.

This is working in IE but in other browsers its showing error.

Any body having idea ?

Okay here is the AS3 code...please check it out

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

}

}

The error

 [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2038"]

3条回答
干净又极端
2楼-- · 2019-08-25 05:49

Hey finally i got the solution. If any body facing like this problem please follow the some basic steps

Here the problem i faced is the file is uploading in IE(All version) but its not working in other browsers.

Then follow these steps

  • -- First try dispatching the HTTPStatusEvent

  • -- Check what error is coming. If the URL is valid it will not give error other wise it will show error responseURL=null

  • -- Then check your server side script path (what you are using to upload the file)

  • -- In my case i have passed the full URL for the file as a path not like (assets/.../fileuploader.php)

  • -- Then the error will be solved

You will find many solution on internet. But the most of the cases to check filereference.IOerrorevent & filereference.HTTPStatusEvent

Refer this link :
http://help.adobe.com//en_US/FlashPlatform/reference/actionscript/3/flashnet/FileReference.html#includeExamplesSummary

查看更多
放我归山
3楼-- · 2019-08-25 06:05

look: Maximum value of maxRequestLength?

I had a same problem I solved with that code below into the web.config to 1Gb file

<system.web>
<httpRuntime maxRequestLength="2097152" />
</system.web>
<system.webServer>
<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483648" />
     </requestFiltering>
 </security>
</system.webServer>
查看更多
混吃等死
4楼-- · 2019-08-25 06:07

I tried do this and resolved my problem

Right after the Flex application initializes, call the remote server method to retrieve the server-session ID. In Java the remote method will look like this:

public String getSessionInfo()
{
return FlexContext.getFlexSession().getId();
}
查看更多
登录 后发表回答