Forum Discussion

VictorCueto3's avatar
VictorCueto3
Copper Contributor
Feb 24, 2025

Maui How to upload a file to web API in .NET 9

Hi, everyone

 

I'm trying to upload an image to an API from a maui project.

 

But when I send the file, the response is always BadRequest. However the API works if I use Postman.

I create a client in a console project and it worked. So I don't know why the same code in .NET MAUI it doesn't work.

Problem is not in URI or something.

I hope you could help me.

Reegrets.

Victor Cueto


API throws the next exception:
Microsoft.AspNetCore.Http.BadHttpRequestException: Required parameter "IFormFile image" was not provided from form file.
   at lambda_method3(Closure, Object, HttpContext, Object)
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass103_2.<<HandleRequestBodyAndCompileRequestDelegateForForm>b__2>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

code

Minimal API:

error:

 

No RepliesBe the first to reply

Resources