上传文件,在AS3服务器上传文件、服务器

2023-09-08 13:59:44 作者:花开花落〃埋葬了谁的青春

如何将文件上传到服务器在AS3?我不想用调用FileReference.browse浏览文件()。我尝试使用的URLLoader获取文件,并转换为的字节数组,但我用的URLVariables其发送到服务器时,它给人的IOError = 2032。我想在服务器上更新数据库。其结构会像 电子邮件(串) sqlite_db(BLOB)

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!

推荐答案

上载过程变得更加容易使用 UploadPostHelper 这是一个伟大的类来创建多部分数据表单:

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.