MultipartMemoryStreamProvider: filename?

前端 未结 1 1950
野趣味
野趣味 2021-02-12 21:24

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

相关标签:
1条回答
  • 2021-02-12 21:54

    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
    
    0 讨论(0)
提交回复
热议问题