File upload with Flex 4.5 FileReference IOError #2038

3.1k Views Asked by At

I am using FileReference in Flex 4.5 to upload files to a Tibco web server. Below is the flex code that I wrote several months ago to handle this. At the time it worked just fine, however now it no longer seems to work and I can't figure out why. I'm pretty positive that nothing has changed with this portion of the code since I wrote it several months ago. When I try to use the function to upload a file I get the following error message: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2038: File I/O Error. URL: http://localhost:1112/CCWS/uploadFile?changeID=1325863504338&fileName=out%2Etxt"]

public function uploadFile():void
{

    var fr:FileReference = new FileReference();

    fr.addEventListener(IOErrorEvent.IO_ERROR,function(event:IOErrorEvent):void{
        Alert.show(event.toString());
    });

    fr.addEventListener(Event.SELECT, function (event:Event):void{

        var uploadURL:URLRequest = new URLRequest(url + "/CCWS/uploadFile" );
        var params:URLVariables = new URLVariables();
        params.fileName = fr.name;
        params.changeID = requestIDText.text;
        uploadURL.data = params;

        fr.upload(uploadURL,"fileContent");

    });

    fr.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, function (event:DataEvent):void{
        var obj:ObjectProxy = new ObjectProxy();
        obj.fileName = fr.name;
        obj.fileID = event.data;

        filesDataProvider.addItem(obj);
    });
    fr.browse();
}

In this instance, url was set to "http://localhost:1112" and the server was running on localhost as well, with an http request listener on port 1112. I know the server is working fine because it hosts other webservices from the same process and they all respond without a hitch (including a file download service).

Using Fiddler2 to monitor the packet traffic, I determined that Flex was never sending the request to the server. I simplified my code to this to see if I could find what was going on: public function uploadFile():void { var fr:FileReference = new FileReference();

    fr.addEventListener(IOErrorEvent.IO_ERROR,function(event:IOErrorEvent):void{
        Alert.show(event.toString());
    });

    fr.addEventListener(Event.SELECT, function (event:Event):void{

        var uploadURL:URLRequest = new URLRequest("http://localhost:1112/" );
        var params:URLVariables = new URLVariables();
        params.fileName = fr.name;
        params.changeID = "1325863504338";
        uploadURL.data = params;

        fr.upload(uploadURL,"fileContent");
    });

    fr.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, function (event:DataEvent):void{
        var obj:ObjectProxy = new ObjectProxy();
        obj.fileName = fr.name;
        obj.fileID = event.data;
        Alert.show(obj.fileName,obj.fileID);
        filesDataProvider.addItem(obj);
    });
    fr.browse();
}

When I attempt to upload a file to "http://localhost/" I get an HTTP 500 response, which makes sense because the index.html file in my apache home directory doesn't handle a file upload. But I can also see the packet information show up in Fiddler2. When I change the url back to "http://localhost:1112/" I again get the same kind of error message and no longer see a packet transaction in Fiddler2.

I tried adding a crossdomain.xml file at http://localhost/crossdomain.xml just in case there might be a crossdomain issue trying to submit to port 1112 (which wouldn't make sense to me, but I tried it all the same). The file contained this:

If anyone has any insight as to why I might be having issues I'd appreciate it.

0

There are 0 best solutions below