0

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"]
UI Dev
  • 689
  • 2
  • 9
  • 31
  • 2
    Could you post some code? Otherwise, there's nothing to work with. – CodeMouse92 Jan 07 '14 at 16:47
  • @JasonMc92 I have edited & added the code. Please check. – UI Dev Jan 08 '14 at 04:27
  • What line does the compiler say the error is showing up on? – CodeMouse92 Jan 08 '14 at 05:10
  • Hey i already mentioned Its an IOEvent error. The Line at fileReference.addEventListener(IOErrorEvent.IO_ERROR, onUploadIoError); In this method the "event.text" says Error #2038 – UI Dev Jan 08 '14 at 05:16
  • Thank you. I knew what error it was, but the line number helps narrow in. – CodeMouse92 Jan 08 '14 at 06:35
  • Okay what to do any idea ? – UI Dev Jan 08 '14 at 06:52
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44776/discussion-between-ria-dev-and-jasonmc92) – UI Dev Jan 08 '14 at 12:13
  • If it's working on IE and not in other browsers, I would check the network HTTP transactions to see what is happening, and compare what IE is sending and what Chrome does. Then you may found out some clue about what is happening. – enriquinho Jan 08 '14 at 12:14
  • Thanks for your reply. Can you please elaborate. I dont know where to check the HTTP transaction. – UI Dev Jan 08 '14 at 12:16
  • Okay i checked it out HTTPStatusEvent.HTTP_STATUS it saying as error as [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=404 redirected=false responseURL=null] – UI Dev Jan 08 '14 at 12:49
  • No, I mean checking the HTTP request/responses, through developer tools in chrome, tab network. Or using Charles proxy. – enriquinho Jan 08 '14 at 13:43
  • Okay ...i got the solution. – UI Dev Jan 08 '14 at 14:25

3 Answers3

0

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

UI Dev
  • 689
  • 2
  • 9
  • 31
0

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>
Community
  • 1
  • 1
0

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();
}
Daniel
  • 1
  • 1