Unable to receive form data in web api c#

I am trying to send the uploaded excel file to web api using XMLHttpRequest but all I receive in web api is an object. How to receive uploaded file in web api?

 upload(file: File): void {
        let formData: FormData = new FormData(),
        xhr: XMLHttpRequest = new XMLHttpRequest();
        formData.append("uploads", file, file.name);
        xhr.open('POST', this._expenseServiceUrl + 'expenses' + '/' + 'massupload', true);
        xhr.send(formData);
}

Web API

        [Route("massupload")]
        [HttpPost]
        public HttpResponseMessage MassUpload([FromUri] dynamic uploads)
        {
            try
            {
                response = Request.CreateResponse(HttpStatusCode.OK, "");
            }
            catch (Exception exception)
            {

            }
            return response;
        }

Answers


You can read the uploaded file from Request.Files

foreach (string fileId in Request.Files)
{
   HttpPostedFileBase file = Request.Files[fileId] as HttpPostedFileBase;
}

Also, you have decorated your uploads parameter with FromUri. You could also change that to FromBody as your file is in your POST body, not the URI.


Need Your Help

Creating representable signature of tags

tags compression signature

Lets say I have items with assigned tags to them, like "blue", "big", "flexible". Lets say I also have a dictionary of all possible tags.

zf2 & doctrine2 ObjectRadio getting an variable criteria from the related entity

forms doctrine-orm zend-framework2 one-to-many radio

I'am trying to make a form for entity content with a OneToMany relation to URL. I want to display all the URL's in a radio input field.