Reputation: 3678
I am trying to upload a file using Flurl using AddFile
.
The resulting IFormFileCollection
is null, although I am able to see the item when looking at Request.Form.Files[0]
with the right content length.
Creating the request:
public Task<HttpResponseMessage> UploadImage(string fileName, MemoryStream stream)
{
stream.Position = 0;
_baseUrl
.AppendPathSegments("uploadImage")
.PostMultipartAsync(mp => mp
.AddFile("files", stream, fileName))
}
Handling the request:
[HttpPost]
[Route("uploadImage")]
public async Task<HttpResponseMessage> UploadImages([FromForm] IFormFileCollection files)
{
//files is null, but Request.Form.Files[0] in the immediate window shows the file.
}
A common problem seems to be a mismatch in the name of the parameter and the name in the Content-Disposition header, but I updated them to both be files
and I am still having the same issue.
Upvotes: 3
Views: 2285
Reputation: 27538
That is strange that it works on my side :
MemoryStream ms = new MemoryStream();
using (FileStream file = new FileStream("txt.txt", FileMode.Open, FileAccess.Read))
file.CopyTo(ms);
ms.Position = 0;
var _baseUrl = "https://localhost:44392/";
var result = await _baseUrl
.AppendPathSegments("uploadImage")
.PostMultipartAsync(mp => mp
.AddFile("files", ms, "txt.txt"));
Result :
Please firstly try with a clean file and use await
for handing request .
Upvotes: 1