Reputation: 619
In my controller I use code below to process multipart form data:
string root = HttpContext.Current.Server.MapPath("~/App_Data");
if (!Directory.Exists(root))
{
throw new QLApplicationException("Error ...");
}
MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(root);
Task<HttpResponseMessage> task = Request.Content.ReadAsMultipartAsync(provider).ContinueWith<HttpResponseMessage>
This works fine except that it only saves the form data into a file at /App_Data. What I need however, is to get the data into a string in my program so I don't have to read it out again from the file. How can I do that? Thanks in advance!
Upvotes: 0
Views: 1416
Reputation: 57939
Just to clarify, MultipartFormDataStreamProvider
only saves any uploaded files into the file system. If you are looking to access the form values, you can do provider.FormData
to get them.
If you are looking to access the uploaded file itself in-memory without saving it as a file on the drive, then you can use MultipartMemoryStreamProvider
which reads all uploaded parts of the incoming request into memory. You can access each of this part by accessing the HttpContents
property on the provider.
Upvotes: 1