上传文件,在AS3服务器 [英] Upload file to server in as3

查看:201
本文介绍了上传文件,在AS3服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文件上传到服务器在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!

推荐答案

上载过程变得更加容易使用<一个href="http://marstonstudio.com/2007/10/19/how-to-take-a-snapshot-of-a-flash-movie-and-automatically-upload-the-jpg-to-a-server-in-three-easy-steps/"相对=nofollow> 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆