Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send multiple files using ASP.net core web api

I need to send multiple files to ASP.net core webApi method.I have tried as shown below.But it always shows as 0 files.Can you tell me why ?

[Route("api/[controller]/[action]")]
[Consumes("application/json", "application/json-patch+json", "multipart/form-data")]
public class DocumentUploadController : CpcpControllerBase
{
    [HttpPost]
    public async Task<List<string>> AddDocument(ICollection<IFormFile> files)
    {
        foreach (var f in files)
        {
            var stream = f.OpenReadStream();
            var name = f.FileName;
        }
    }
}

Postman :

enter image description here

But I can send 1 file as shown below.It's working fine.

[HttpPost]
public async Task<string> AddDocument(IFormFile file)
{
        var stream = file.OpenReadStream();
        var name = file.FileName;           
}
like image 344
Sampath Avatar asked Jan 04 '23 17:01

Sampath


1 Answers

Replace key file1 by files in postman. It works for me.

like image 131
Janak Avatar answered Jan 07 '23 07:01

Janak