通过ActionScript 3.0上传使用HTTP POST一个zip文件 [英] upload a zip file using HTTP POST via actionscript 3.0

查看:197
本文介绍了通过ActionScript 3.0上传使用HTTP POST一个zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用拖放在我的台式机的Flex 4.6应用程序的视图中创建一个zip文件。

I have a zip file that is created using drag and drop on a view in my desktop Flex 4.6 app.

这会触发会自动上传zip文件的服务。

This triggers a service that will automatically upload the zip file.

我可以使用下面的code发送的元数据的zip文件到服务器。

I am able to use the following code to send metadata about the zip file to the server.

        var urlRequest:URLRequest = new URLRequest(PUBLISH_ZIP_FILE_URL);
        // set to method=POST
        urlRequest.method = URLRequestMethod.POST;          



        var params:URLVariables = new URLVariables();



        params['data[File][title]'] = 'Title1';
        params['data[File][description]'] = 'desc';         
        // params['data[File][filename]'] =  I am not sure exactly what to use here 
        // If this is a webpage, I expect to use input type="file" with the name as data[File][filename]


        urlRequest.data = params;

        addLoaderListeners();

        // set it such that data format is in variables
        loader.dataFormat = URLLoaderDataFormat.VARIABLES;

        loader.load(urlRequest);

我读<一href="http://stackoverflow.com/questions/8837619/using-http-post-to-upload-a-file-to-a-website">Using HTTP POST将文件上传到网站

不过,他们立刻用字节数组,这我不知道如何转换我的zip文件都开始了。

However, immediately they start off with ByteArray, which I am not sure how to convert my zip file at all.

请指教。

推荐答案

尴尬,但我发现我的答案42分钟后,我张贴的问题。

Embarrassing but I found my answer 42 mins after I posted the question.

的橡皮鸭子的问题一点点解决回事。

A little bit of a rubber duck problem solving going on here.

http://www.codinghorror.com/博客/ 2012/03 /橡胶鸭子问题solving.html

简短的回答:使用File类,具体方法<一href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#upload%28%29"相对=nofollow>上传它是从<一个扩展href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html"相对=nofollow>的FileReference 类。

Short answer: Use File class and specifically the method upload which is extended from the FileReference class.

的回答:

        var urlRequest:URLRequest = new URLRequest(PUBLISH_ZIP_FILE_URL);
        // set to method=POST
        urlRequest.method = URLRequestMethod.POST;

        var params:URLVariables = new URLVariables();

        params['data[File][title]'] = 'Title1';
        params['data[File][description]'] = 'desc';

        // this is where we include those non file params and data
        urlRequest.data = params;


        // now we upload the file
        // this is how we set the form field expected for the file upload
        file.upload(urlRequest, "data[File][filename]");

这篇关于通过ActionScript 3.0上传使用HTTP POST一个zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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