How to make jQuery to upload files a plugin only once for all files on upload?

I am using sails.js to create a website. I have a model called timeline . It has some text fields along with a collection called pictures . Each timeline can have several pictures . I want to update all these fields at once when the user clicks save . I am using jQuery file loader for multi-threaded download.

The problem is that downloading a jQuery file causes my backend file download once for each uploaded image. I need to update other text fields only once, and they need to be updated before creating pictures records, since for each image there must be an ID timeline associated with them.

Are there asynchronous tasks? I don’t feel this, since the JQuery file loader calls my server several times, I don’t think I can push tasks and update other fields using asynchronous parallel. I could do this if it were one call to download.

I am going to save two submit buttons - one for text fields and one for uploading files, but I really don't like this. It would be great if someone would tell me about this.

+2
asynchronous jquery-file-upload asyncfileupload
source share
3 answers

Setting SingleFileUploads to false did not help with the jQuery file loader, as it seems the error was discussed above. Therefore, I have returned this truth.

I divided the inputs into two separate forms: one for entering text fields and one for files (which goes through the jQuery file loader). For the form of the text fields, I saved a visible button that the user can click. For another, I hid the button. Thus, as soon as the user clicks on the visible button, I send only text input and create a database record in the backend (this is done using the AJAX call) and in the success field of the AJAX call, I .click() hidden button if the number of files is more than 0 .

+1
source share

If I understand your question correctly, I think you need to check the jquery.fileupload.js file around line 112, try changing singleFileUploads: false,

+2
source share
 var counter = 0; var allFilesObj = Array(); 

req.file ('files []') flat download ({

  saveAs: function (__newFileStream, cb) { var fileObj = {}; var extension = __newFileStream.filename.split('.').pop(); var original_name = __newFileStream.filename; fileObj.original_name = original_name; fileObj.name = "Thename"; fileObj.ext = extension; fileObj.path = uploadpath+"The name"+ "." + extension; counter++; allFilesObj.push(fileObj); cb(null, uploadpath+"The name"+ "." + extension;); } }, function whenDone(err, uploadedFiles) { if (err) { console.log("ERROR"); console.log(err); return res.negotiate(err); } else { async.each(allFilesObj, function (row, done) { var index = allFilesObj.indexOf(row); row.col1 = req.param('col1'); row.col2 = req.param('col2'); row.col3 = req.param('col3'); done(); }, function (err) { if (err) { res.send("Error 500 , complete object array Defunct"); } //DATABASE INSERT YourModel.create(allFilesObj, function batchFileCreated(err, user) { if (err) { return res.send(err); } console.log("done"); 

//req.session.messages ['success'] [0] = "Files uploaded successfully"; // returns res.redirect (req.get ('referer'), {files: uploadedFiles, textParams: req.params.all ()}); return res.ok ({files: uploadedFiles, textParams: req.params.all ()}); });

  }); } } }); 
+1
source share

All Articles