Search code examples
c#asp.net-corejquery-file-upload

How to access additional form data sent from jquery file upload in asp.net core?


I am using jquery file upload to upload large files in chunks to server. I need to send additional data to server along with the file.

I found this article that suggests adding formData as below.

$form = $('#fileupload').fileupload({
            maxChunkSize: 3000000,
            url: '/FileAPI/Upload',
            formData: { example: 'test' }
         });

How can I access the formData from HttpContext.Request in asp.net core ? Where is it available? Thanks for any suggestions.

[HttpPost]
[Route("Upload")]

public ActionResult Upload()
{
    var CurrentContext = HttpContext.Request;
}

Solution

  • How can I access the formData from HttpContext.Request in asp.net core ?

    From the article you provide , "formData object, formData: {example: 'test'} will arrive on server-side as POST parameter"

    You could also try the following method to get it :

     [HttpPost]
     [Route("Upload")]
     public void Upload()
     {
            var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());
           //In that case, you could iterate over your dictionary or you can access values directly:
            var CurrentContext = dict["example"];
      }