Question

I have a requirement, where I have to upload file using WEB API. So created a api controller for Post and handled the Multi-part form data and I could successfully upload the files. But I need to pass an complex type with properties such as FileName, Description, FormId, etc... along with the file. So how to achieve this using single Post Controller. For eg.)

public HttpResponseMessage Post([FromBody] MyComplexType myType)
{
    //Here I get the files from Request.Content.ReadAsAsyncStream();
    // myType is always null. 
}

Also from Client Side (Javascript and .NET Client) I can post either Mutlipart Formdata or the Complex type. But I need to do both in same request.

Please help....

Was it helpful?

Solution

Have you looked into using MultipartFormDataProvider where the request is a multipart request having 'formurlencoded' data + files?...but if your request is like 'json' data + files, then you can use MultipartMemoryStreamProvider...if files are huge and memory usage is a concern, you can create a custom MultipartStreamProvider...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top