Ниже приведен мой контроллер
Код: Выделить всё
public class FileUploadController : ControllerBase
{
[HttpPost]
[Route("fileupload")]
public async Task PackIt(List files)
{
if (files == null || files.Count == 0)
{
return BadRequest("No files uploaded.");
}
return Ok(new { message = "Files received successfully." });
}
}
Код: Выделить всё
async function sendLogicFiles(fileHandles: FileSystemFileHandle[]) {
try {
const formData = new FormData()
fileHandles.forEach(async (file, index) => {
const fileHandle = fileHandles[index]
const _file = await fileHandle.getFile()
formData.append(`files[${index}]`, _file)
})
const response = await fetch('fileupload', {
method: 'POST',
body: formData,
})
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText)
}
const responseData = await response.json()
console.log('Success:', responseData)
} catch (error) {
console.error('Error:', error)
}
}
Код: Выделить всё
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"files": [
"The files field is required."
]
},
"traceId": "00-2073e137b176760a1c75cd95b8a542dc-6f64030c375117eb-00"
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... controller
Мобильная версия