question

CoreyFleig-6304 avatar image
0 Votes"
CoreyFleig-6304 asked ZhiLv-MSFT edited

How to add many files to Form.Request.Files

I have a project where I'm trying to simulate adding multiple files for upload to MVC.
Instead of using <input type=file multiple> a user would like to use several instances
of a dropzone, one for each image/thumbnail.

So imagine a page with 10 drop zones, where each drop zone would accept one selected file.

I saw a code snippet and wondered if I can modify it, and then somehow loop through all the file controls,
and add each file, one at a time, into a global formdata variable, sort of like this: (some pseudocode is included):

 var data = new FormData();

 for (int idx = 0; idx <= 9; idx)
 {
     data.set("file", $("#uploadControl").val());    // Somehow add each data.set from 10 controls, maybe using data.append?????
 }

 $.ajax({
    type: "POST",
    url: "upload",
    data: data,
    contentType: false,
    processData: false
 });


dotnet-aspnet-core-general
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @CoreyFleig-6304,

  var data = new FormData();
  for (int idx = 0; idx <= 9; idx)
  {
      data.set("file", $("#uploadControl").val());    // Somehow add each data.set from 10 controls, maybe using data.append?????
  }

First, to use the FormData, as you said, we need to use the FormData.append() method.

Second, since you are using the DropZone JS plugin to upload the images, it is better to check whether it has the relate method to get the upload files. And since this issue relates the DropZone JS, if you can't find the relates method, you can post this question to DropZone JS forum.

0 Votes 0 ·

0 Answers