//添加post字段
task.addData("client", "HelloH5+");
task.addData("uid", getUid());
for(var i=0;i<files.length;i++){
var f=files[i];
task.addFile(f.path,{key:f.name});
task.addEventListener( "statechanged", onStateChanged, false );
task.start();
}
日志如下:
[LOG] : 上传成功:{"strings":{"client":"HelloH5+","uid":"101938915"},"error":"0","files":{"uploadkey1":{"name":"IMG_0001(34).JPG","url":"files\/IMG_0001(34).JPG","type":"image\/jpeg","size":626563}}}
[LOG] : Upload success: {"UUID":"uploader91435031729055","url":"http://demo.dcloud.net.cn/helloh5/uploader/upload.php","state":4,"options":{"method":"POST"},"uploadedSize":626959,"totalSize":626959,"responseText":"{\"strings\":{\"client\":\"HelloH5+\",\"uid\":\"101938915\"},\"error\":\"0\",\"files\":{\"uploadkey1\":{\"name\":\"IMG_0001(34).JPG\",\"url\":\"files\/IMG_0001(34).JPG\",\"type\":\"image\/jpeg\",\"size\":626563}}}","method":"POST","timeout":120,"retry":3,"priority":1,"eventHandlers":{"statechanged":{"type":"statechanged","handles":[null,null,null,null],"capture":false}}}
[LOG] : Upload success: {"UUID":"uploader91435031729055","url":"http://demo.dcloud.net.cn/helloh5/uploader/upload.php","state":4,"options":{"method":"POST"},"uploadedSize":626959,"totalSize":626959,"responseText":"{\"strings\":{\"client\":\"HelloH5+\",\"uid\":\"101938915\"},\"error\":\"0\",\"files\":{\"uploadkey1\":{\"name\":\"IMG_0001(34).JPG\",\"url\":\"files\/IMG_0001(34).JPG\",\"type\":\"image\/jpeg\",\"size\":626563}}}","method":"POST","timeout":120,"retry":3,"priority":1,"eventHandlers":{"statechanged":{"type":"statechanged","handles":[null,null,null,null],"capture":false}}}
[LOG] : Upload success: {"UUID":"uploader91435031729055","url":"http://demo.dcloud.net.cn/helloh5/uploader/upload.php","state":4,"options":{"method":"POST"},"uploadedSize":626959,"totalSize":626959,"responseText":"{\"strings\":{\"client\":\"HelloH5+\",\"uid\":\"101938915\"},\"error\":\"0\",\"files\":{\"uploadkey1\":{\"name\":\"IMG_0001(34).JPG\",\"url\":\"files\/IMG_0001(34).JPG\",\"type\":\"image\/jpeg\",\"size\":626563}}}","method":"POST","timeout":120,"retry":3,"priority":1,"eventHandlers":{"statechanged":{"type":"statechanged","handles":[null,null,null,null],"capture":false}}}
[LOG] : Upload success: {"UUID":"uploader91435031729055","url":"http://demo.dcloud.net.cn/helloh5/uploader/upload.php","state":4,"options":{"method":"POST"},"uploadedSize":626959,"totalSize":626959,"responseText":"{\"strings\":{\"client\":\"HelloH5+\",\"uid\":\"101938915\"},\"error\":\"0\",\"files\":{\"uploadkey1\":{\"name\":\"IMG_0001(34).JPG\",\"url\":\"files\/IMG_0001(34).JPG\",\"type\":\"image\/jpeg\",\"size\":626563}}}","method":"POST","timeout":120,"retry":3,"priority":1,"eventHandlers":{"statechanged":{"type":"statechanged","handles":[null,null,null,null],"capture":false}}}
2 个回复
DCloud_App_Array
一个task任务只应该掉一次,为啥要调用多次start呢,上面的代码是不是应该这样:
注意:files对象是什么?不能是<input type="file">对象,里面的path路径必须有效,如果无效是无法上传的
大树哥 (作者) - 有没有iOS的兼职
我想我意识到问题了。
选择的多个文件,上传都没问题,都能上传成功。
现在的upload是一次性将多个文件同时上传的,并不能拿到每个单独的文件的状态变化。
我当时的需求是,我添加了5个文件,我为每个文件绑定生成一个上传请求,同时绑定一个回调。