2

In the code shown here, the PostFormData method receives the files parameter as it should but the Request object is null and I don't know why.

public class UploadController : ApiController
{
    private readonly IHttpContextAccessor _httpContextAccessor;
    private readonly IWebHostEnvironment _webHostEnvironment;

    public UploadController(IHttpContextAccessor httpContextAccessor,
                            IWebHostEnvironment webHostEnvironment)
    {
        _httpContextAccessor = httpContextAccessor;
        _webHostEnvironment = webHostEnvironment;
    }

    [HttpPost]
    public async Task<IHttpActionResult> PostFormData(List<IFormFile> files, CancellationToken cancellationToken)
    {
        try 
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
        }
    }
}

Network headers

:authority
localhost:7196
:method
POST
:path
/upload/PostFormData
:scheme
https
accept
*/*
accept-encoding
gzip, deflate, br, zstd
accept-language
en-GB,en;q=0.9,en-US;q=0.8,en-AU;q=0.7
cache-control
max-age=0
content-length
1293
content-type
multipart/form-data; boundary=----WebKitFormBoundaryy5g1PB4Exs6s0PYA
dnt
1
origin
null
priority
u=1, i
sec-ch-ua
"Not;A=Brand";v="99", "Microsoft Edge";v="139", "Chromium";v="139"
sec-ch-ua-mobile
?0
sec-ch-ua-platform
"Windows"
sec-fetch-dest
empty
sec-fetch-mode
cors
sec-fetch-site
cross-site
user-agent
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0
0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.