Answer the question
In order to leave comments, you need to log in
Uploading a file in .Net Core 2 WebApi (from Postman), who has any successful experience?
there is no experience on all points of the subject ((the note https://janaks.com.np/file-upload-asp-net-core-web-api/
was taken as a basis,
I try to load from Postman (yes, in the web frontend it’s generally zero, which yes that is ((
variants of the tried
//[Consumes("multipart/from-data", "application/octet-stream")]
[Consumes("application/json", "application/json-patch+json", "multipart/from-data", "application/x-www-form-urlencoded")]
//[Consumes("application/json", "multipart/from-data")]
//[Consumes("multipart/from-data")]
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]
//public async Task<IActionResult> PostAttachmentItem([FromBody] IFormFile file)
//public async Task<IActionResult> PostAttachmentItem(IFormFile file)
public async Task<IActionResult> PostAttachmentItem(List<IFormFile> files)
[
][
]IFormFile file
List<IFormFile> files
null
Answer the question
In order to leave comments, you need to log in
the question is closed. Request.Form.Files
found here https://qa-help.ru/questions/aspnet-core-rc2-zagru...
ps
[HttpPost]
public async Task<IActionResult> PostAttachmentItem()
{
var files = Request.Form.Files;
long size = files.Sum(f => f.Length);
foreach (var file in files)
if (file.Length > 0)
using (var stream = new MemoryStream())
{
await file.CopyToAsync(stream);
db.AttachmentItems.Add(new AttachmentItem
{
FileName = file.FileName,
Body = stream.ToArray()
});
}
await db.SaveChangesAsync();
return Ok(new { count = files.Count, size });
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question