Hongyang Du
Hongyang Du

Reputation: 729

how to upload a file to asp.net core backend with http

Now I use Asp.net core as the server framework. I want to know how to upload a file to an Asp.net core server? I use web api but not the web application. So form submit is no use. The code below doesn't work.

[HttpPost("uploadImage/{accountGuid}")]
public async Task<string> UploadTargetImage(ICollection<IFormFile> files,Guid accountGuid)
{   
     if (files == null) throw new Exception("File is null");
     if (files.Count == 0) throw new Exception("File is empty");
}

I use fiddler to test the API. Like below: see the fiddler post image

The result of api is File is empty.So the server didn't get the post file. What should I do? It puzzles me for a long time.

Upvotes: 0

Views: 543

Answers (1)

Hongyang Du
Hongyang Du

Reputation: 729

I hava just fix it! The input name in POST must be the same as method param in ASP.NET.

Upvotes: 1

Related Questions