We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I can get files with minimal api. I can't get files with mvc controller.
No response
MapPost:
app.MapPost("/MinimalApi/Upload", async (IFormFileCollection files) => { await Task.CompletedTask; return Results.Ok(files.Count); });
MapController:
[ApiController] [Route("api/[controller]")] public class TestController : ControllerBase { // /Test/Upload [HttpPost("Upload")] public async Task<IActionResult> Upload([FromForm] IFormFileCollection files) { await Task.CompletedTask; return Ok(files.Count); } }
Call await UploadAsync(urlMinimalApi) and await UploadAsync(urlMvcController)
await UploadAsync(urlMinimalApi)
await UploadAsync(urlMvcController)
the responseContent of MinimalApi is 2 (expected). the responseContent of MvcController is 0 (unexpected).
private async Task UploadAsync(string url) { using HttpClient httpClient = new(); var content = new MultipartFormDataContent(); using var stream1 = new MemoryStream("Content1"u8.ToArray()); var fileContent1 = new StreamContent(stream1); fileContent1.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream"); content.Add(fileContent1, "File1", "File1.txt"); using var stream2 = new MemoryStream("Content2"u8.ToArray()); var fileContent2 = new StreamContent(stream2); fileContent2.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream"); content.Add(fileContent2, "File2", "File2.txt"); var response = await httpClient.PostAsync(url, content); response.EnsureSuccessStatusCode(); string responseContent = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseContent); }
7.0.304
What's wrong with my code? Or there is a bug in http client?
Thanks for your help.
The text was updated successfully, but these errors were encountered:
Update:
if the HTTP content item name is "files", then the minimal api works the same as mvc controller.
content.Add(fileContent1, "files", "File1.txt"); content.Add(fileContent2, "files", "File2.txt");
It seems that because of minimal api lacks form binding support (#39430), cause the inconsistent behavior with mvc controller.
minimal api
mvc controller
Sorry, something went wrong.
No branches or pull requests
Is there an existing issue for this?
Describe the bug
I can get files with minimal api.
I can't get files with mvc controller.
Expected Behavior
No response
Steps To Reproduce
MapPost:
MapController:
Call
await UploadAsync(urlMinimalApi)
andawait UploadAsync(urlMvcController)
the responseContent of MinimalApi is 2 (expected).
the responseContent of MvcController is 0 (unexpected).
Exceptions (if any)
No response
.NET Version
7.0.304
Anything else?
What's wrong with my code? Or there is a bug in http client?
Thanks for your help.
The text was updated successfully, but these errors were encountered: