Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultipartMemoryStreamProvider: filename?

I already asked here how I can read uploaded files in Web Api without the need to save them. This question was answered with the MultipartMemoryStreamProvider, but how do I get the file name with this method to derive the type of the uploaded file from it?

Kind regards

like image 489
SharpNoiZy Avatar asked Jan 23 '13 08:01

SharpNoiZy


1 Answers

There is an example in this DotNetNuke Code here (See the PostFile() method).

Updated based on @FilipW comment...

Get the content item you require and then access the filename property.

Something like this :

        var provider = new MultipartMemoryStreamProvider();
        var task = request.Content.ReadAsMultipartAsync(provider).
             ContinueWith(o =>
                 {
                     //Select the appropriate content item this assumes only 1 part
                     var fileContent = provider.Contents.SingleOrDefault();

                     if (fileContent != null)
                     {
                         var fileName = fileContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);
                     }
                 });//Ending Bracket
like image 72
Mark Jones Avatar answered Sep 29 '22 05:09

Mark Jones