1

I use DropzoneJS library to upload files on my website. Now, I want to create my own function to upload queued files.

I know, I can get all these files in that way:

files = myDropzone.getQueuedFiles();

But how I can now create an ajax request to send these files? I need something like file_get_contents() function (as in PHP) to get content of these files and then send ajax post with that params.

Thanks for your help.

Pavlo K
  • 151
  • 9
  • you can specify your url you want to be fired when all your files gets processed – Shubham Jan 23 '19 at 07:43
  • url: "class/inserir.php?funcao=teste", – Shubham Jan 23 '19 at 07:45
  • I have a long form on my website and I send everything in this request. In DropzoneJS I have to set next URL to upload files - I do not want it. I want to add to my current ajax these files and send one request but I don't know how I can create this ajax request using `getQueuedFiles()` function. – Pavlo K Jan 23 '19 at 07:46

1 Answers1

0

Perhaps you could give a bit more context. If I understand correctly:

function sendFile(file) {
   // Do ajax things here e.g. check out the link below
}


const files = myDropzone.getQueuedFiles(); // I'm assuming this returns an array?
files.forEach(sendFile) // For each loops over the array, and calls the sendFile function with as first parameter the current item in the array, which is in your case one of your files

To make an AJAX request with vanilla javascript: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest

Danie A
  • 811
  • 8
  • 18
  • is it possible to send ajax request in that way: https://stackoverflow.com/a/24939229/10210622 ? – Pavlo K Jan 23 '19 at 08:28
  • that's using jQuery. Checkout https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest to do it without jQuery – Danie A Jan 23 '19 at 08:34