How to retrieve JSON result after file upload via actionscript

守給你的承諾、 提交于 2019-12-11 04:57:59

问题


I know how to upload a file using action script

See upload a zip file using HTTP POST via actionscript 3.0 for details.

Code replicated here:

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

The web app responsible for accepting the file upload will return a JSON string containing details such as file size, id number, etc.

How do I access this JSON result string in my actionscript?


回答1:


From the FileReference docs, you need to add a handler to your FileReference instance for the uploadCompleteData event:

import flash.events.*;

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

private function uploadCompleteDataHandler(event:DataEvent):void  
{
     trace("uploadCompleteData data: " + event.data);
}


来源:https://stackoverflow.com/questions/10914363/how-to-retrieve-json-result-after-file-upload-via-actionscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!