在流星中使用弹弓进行循环

时间:2015-04-08 09:58:36

标签: file-upload meteor meteor-slingshot

我正试图在流星中使用弹弓包进行fileupload。它适用于单个文件。但我的要求是我使用多个文件输入,并且对于每个文件输入,我想将文件发送到s3。 这是我的客户端/ upload.js

'click #saveImgs': function(e) {
  for(var i=1; i<6;i++){
    var fileList= document.getElementById('file_'+i);
    var f= fileList.files[0];
    if(f){
      var uploader = new Slingshot.Upload("images");          
      uploader.send(f, function (error, downloadUrl) {
        if (error) {
          alert(error);
            console.error('Error uploading', uploader.xhr.response);
        }
        else {
          console.log(downloadUrl);
        }
      });     
    }
    else{
      alert("no file");
    }       
  } 
}

我的upload.html是这样的:

<h3>Multiple upload</h3>
<br>
<input type=file id="file_1" />

<br>
<input type=file id="file_2" />

<br>
<input type=file id="file_3" />

<br>
<input type=file id="file_4" />

<br>
<input type=file id="file_5" />

<br>
<input type=button value="Upload" id="saveImgs" />

它是第一次上传的网址,但在此之后它会提供异常并打破下一个流程。

I20150408-15:06:42.169(5.5)? Exception while invoking method 'slingshot/uploadRequest' Error: Did not check() all arguments during call to 'slingshot/uploadRequest'
I20150408-15:06:42.169(5.5)?     at [object Object]._.extend.throwUnlessAllArgumentsHaveBeenChecked (packages/check/match.js:357:1)
I20150408-15:06:42.169(5.5)?     at Object.Match._failIfArgumentsAreNotAllChecked (packages/check/match.js:112:1)
I20150408-15:06:42.169(5.5)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1614:1)
I20150408-15:06:42.170(5.5)?     at packages/ddp/livedata_server.js:648:1
I20150408-15:06:42.170(5.5)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150408-15:06:42.170(5.5)?     at packages/ddp/livedata_server.js:647:1
I20150408-15:06:42.170(5.5)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150408-15:06:42.170(5.5)?     at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1)
I20150408-15:06:42.171(5.5)?     at packages/ddp/livedata_server.js:546:1

1 个答案:

答案 0 :(得分:1)

删除审计参数检查包或检查方法中的所有参数以使其工作。

(使其正式回答)