I have a code that will send files to be recorded, at the moment I can only record 1 file, the rest does not come, thanks for the help!
<script>
swal({
input: 'file',
inputAttributes: {
'multiple':'multiple',
'accept': '*',
'aria-label': 'Upload your profile picture'
}
})
.then(({value: file}) => {
if (file) {
const reader = new FileReader
reader.onload = (arquivos) => {
let uploadForm = new FormData();
uploadForm.append("arquivo", file);
$.ajax({
type: 'POST',
url: 'http://localhost:59360/Home/IncluirImagemUsuario',
mimeType: 'multipart/form-data',
contentType: false,
processData: false,
data: uploadForm,
success: function (result) {
result = JSON.parse(result)
if (result.Erro) {
return erro(result.Erro.Mensagens.join('<br>'))
}
}
});
}
reader.readAsDataURL(file)
}
})
</script>
In the controller I have:
[HttpPost]
public ActionResult IncluirImagemUsuario()
{
foreach (string item in Request.Files)
{
HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase;
string fileName = file.FileName;
string UploadPath = "~/Content/Arquivos";
if (file.ContentLength == 0)
continue;
if (file.ContentLength > 0)
{
//grava a imagem da pasta
string path = Path.Combine(HttpContext.Request.MapPath(UploadPath), fileName);
string extension = Path.GetExtension(file.FileName);
file.SaveAs(path);
}
}
return Json(new
{
message = "Registro inserido com sucesso",
success = true
});
}