上传文件到服务器 as3 [英] Upload file to server in as3
问题描述
如何在 as3 中将文件上传到服务器?我不想使用 FileReference.browse() 浏览文件.我尝试使用 URLLoader 来获取文件并转换为 byteArray,但是当我使用 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.
这篇关于上传文件到服务器 as3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!