file-uploadmeteormeteor-slingshot

Using slingshot in for loop in meteor


I'm trying to use slingshot package for fileupload in meteor. It is working fine for single file. But my requirement is I'm using multiple file inputs and for each file input I want to send file to s3. This is my client/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");
    }       
  } 
}

And my upload.html is like this:

<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" />

It is returning url for first upload but after that it is giving exception and breaking next process.

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

Solution

  • Remove the audit argument checks package or check all arguments in methods to make it work.

    (to make it an official answer)