简体   繁体   English

通过ActionScript上传文件后如何检索JSON结果

[英]How to retrieve JSON result after file upload via actionscript

I know how to upload a file using action script 我知道如何使用动作脚本上传文件

See upload a zip file using HTTP POST via actionscript 3.0 for details. 有关详细信息,请参见使用HTTP POST通过actionscript 3.0上传zip文件

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. 负责接受文件上传的Web应用将返回一个JSON字符串,其中包含诸如文件大小,ID号等详细信息。

How do I access this JSON result string in my actionscript? 如何在我的动作脚本中访问此JSON结果字符串?

From the FileReference docs , you need to add a handler to your FileReference instance for the uploadCompleteData event: FileReference docs中 ,您需要为您的uploadCompleteData事件的FileReference实例添加一个处理程序:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM