In my ASP.NET Core backend, I have a controller function that looks like this:
[HttpPost]
[Route("documents/upload")]
public async Task<IActionResult> UploadFile(ICollection<IFormFile> files)
{
...
}
In my front-end, I call the function like this:
var postSettings = {
method: 'POST',
credentials: 'include',
mode: 'cors'
}
uploadDocuments( files ) {
var data = new FormData();
data.append('files', files);
postSettings.body = data;
return fetch(endPoint + '/documents/upload', postSettings);
}
If "files" is a single file - not an array with one file, but a single File object - UploadFile
is called with an ICollection<IFormFile>
containing the single file.
If "files" is a list of files, either a FileList or an array of File objects, UploadFile
is called with an empty ICollection<IFormFile>
.
How do I submit a list of files in such a way that they can be parsed as an ICollection<IFormFile>
?
Reference Uploading multiple files at once - with Fetch
Reference Uploading small files with model binding