Upload file to server in as3

情到浓时终转凉″ 提交于 2020-01-03 06:03:07

问题


How to upload a File to server in as3? I don't want to browse file by using FileReference.browse(). I tried using URLLoader to get the file and convert to byteArray but as I send it to server using URLVariables it gives IOError=2032. I want update database on the server. The structure would be like email (string) sqlite_db (Blob)

I have to send both of these variables inside one request. Any idea!


回答1:


The upload process is made much easier by using the UploadPostHelper which is a great class to create multipart data forms:

ByteArray byteArray = [YOUR FILE DATA];

var urlRequest : URLRequest = new URLRequest();
urlRequest.url = 'http://your.server.com/destination';
urlRequest.contentType = 'multipart/form-data; boundary=' + UploadPostHelper.getBoundary();
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = 
    UploadPostHelper.getPostData( 
        'filename.ext', 
        byteArray, 
        { 
            email:"emailParameter", 
            other:"otherParameter" 
        } );
urlRequest.requestHeaders.push( new URLRequestHeader( 'Cache-Control', 'no-cache' ) );

// create a loader & send the file to the server;
var urlLoader : URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load( urlRequest );

And of course you can listen to the complete event and pass back any information from your server. Hope that helps.



来源:https://stackoverflow.com/questions/12245682/upload-file-to-server-in-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!