Вопрос по http, post, file-upload – загрузить ZIP-файл, используя HTTP POST через actionscript 3.0
У меня есть zip-файл, созданный с помощью перетаскивания в моем приложении Flex 4.6.
Это запускает службу, которая автоматически загружает 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 и, в частности, методзагружать который расширен отСсылка на файл учебный класс.
Длинный ответ:
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]");