I have an ASP.NET Core Web API where an endpoint uploads a PDF file. The current method to upload to physical storage (the hard disk) is this:
[HttpPost]
public async Task<ActionResult> Upload([FromForm] UploadModel uploadModel)
{
var fileName = System.IO.Path.Combine(_environment.ContentRootPath,
"uploads",
uploadModel.ImeiOrSerial + "" + uploadModel.EquipmentInvoice.FileName);
await uploadModel.EquipmentInvoice.CopyToAsync(
new System.IO.FileStream(fileName, System.IO.FileMode.Create));
using (var context = _context)
{
var equipment = new Equipment();
equipment.TypeOfEquipment = uploadModel.TypeOfEquipment;
equipment.EquipmentBrand = uploadModel.EquipmentBrand;
equipment.ModelOrReference = uploadModel.ModelOrReference;
equipment.ImeiOrSerial = uploadModel.ImeiOrSerial;
equipment.Path = uploadModel.ImeiOrSerial + "" + uploadModel.EquipmentInvoice.FileName;
_context.Equipment.Add(equipment);
await _context.SaveChangesAsync();
return Ok(await _context.Equipment.FindAsync(equipment.IdEquipment));
}
}
If I do this in development, everything works perfectly, I get the name of the PDF invoice and it gets in the uploads file inside the solution directory
But if try to do this on my IIS web server, it doesn't work.
I enabled swagger in production mode to see what error the swagger was throwing, but I only get this:
I have no clue what I'm doing wrong.
UPDATE
I wrap my post method in a try catch and now it shows me the following error: