Upload zip file using HTTP POST through ActionScript 3.0

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

This starts a service that automatically downloads the zip file.

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

I read https://stackoverflow.com/questions/8837619/using-http-post-to-upload-a-file-to-a-website

However, right away they start with ByteArray, and I'm not sure how to convert a zip file at all.

Please inform.

+2
source share
1 answer

I am embarrassed, but I found the answer 42 minutes after I posted the question.

A little bit about solving the problem with rubber duck passing here.

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

Short answer: use the File class and, in particular, the upload method, which is extended from FileReference .

Long answer:

  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]"); 
+4
source

Source: https://habr.com/ru/post/1415032/


All Articles