大树哥
大树哥
  • 发布:2015-06-23 12:45
  • 更新:2015-06-25 16:51
  • 阅读:3136

uploader中,多文件上传时,只能发出一次UploadStateChangedCallback

分类:HTML5+
    //添加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}}}

2015-06-23 12:45 负责人:无 分享
已邀请:
DCloud_App_Array

DCloud_App_Array

一个task任务只应该掉一次,为啥要调用多次start呢,上面的代码是不是应该这样:

    //添加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();

注意:files对象是什么?不能是<input type="file">对象,里面的path路径必须有效,如果无效是无法上传的

大树哥

大树哥 (作者) - 有没有iOS的兼职

我想我意识到问题了。

上传成功,包含了多个文件的信息
{"strings":{"client":"HelloH5+","uid":"72313071"},"error":"0","file
s":{"uploadkey1":{"name":"IMG_0001(2)[1].JPG","url":"files\/IMG_0001(2)[1].JPG",
"type":"image\/jpeg","size":626563},"uploadkey2":{"name":"IMG_0002(1)[2].JPG","u
rl":"files\/IMG_0002(1)[2].JPG","type":"image\/jpeg","size":336676},"uploadkey3"
{"name":"IMG_0003(1)[3].JPG","url":"files\/IMG_0003(1)[3].JPG","type":"image\/j peg","size":483787}}}

选择的多个文件,上传都没问题,都能上传成功。
现在的upload是一次性将多个文件同时上传的,并不能拿到每个单独的文件的状态变化。

我当时的需求是,我添加了5个文件,我为每个文件绑定生成一个上传请求,同时绑定一个回调。

该问题目前已经被锁定, 无法添加新回复