actionscript-3 - 通过 Actionscript 3.0 使用 HTTP POST 上传 zip 文件

标签 actionscript-3 http post file-upload

我有一个 zip 文件,该文件是通过在桌面 Flex 4.6 应用程序中的 View 上拖放而创建的。

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

我可以使用以下代码将有关 zip 文件的元数据发送到服务器。

        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);

我已阅读https://stackoverflow.com/questions/8837619/using-http-post-to-upload-a-file-to-a-website

但是,他们立即开始使用 ByteArray,我根本不知道如何转换我的 zip 文件。

请指教。

最佳答案

很尴尬,但我在发布问题 42 分钟后找到了答案。

这里正在解决一些橡皮鸭问题。

http://www.codinghorror.com/blog/2012/03/rubber-duck-problem-solving.html

简短回答:使用 File 类,特别是方法 upload这是从 FileReference 扩展而来的类。

长答案:

        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 - 通过 Actionscript 3.0 使用 HTTP POST 上传 zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10772616/

相关文章:

actionscript-3 - 垃圾收集到底是什么?在 ActionScript 3.0 中你是如何做到的?

Node.js http 服务器 : what happens to the unread body of the POST request?

http - 如何使用 Perl6 与 Github API 交互?

Laravel 重定向为 POST

Java HttpPost 到 php 页面

Facebook Graph API 发布带有页面墙链接的消息

actionscript-3 - Flex中的konami代码

flash - Flash中的流音频播放多次,重叠

http - 为什么从磁盘缓存返回http 200代码,响应头中既没有过期也没有缓存控制?

Ruby:如何使用 Curb 发送 JSON POST 请求?