问题描述
我已经在这里问我怎么能读取网页API上传的文件,而不需要拯救他们。
这个问题得到的回答与MultipartMemoryStreamProvider,但如何获取文件名用这种方法来从中获得上传文件的类型?
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?
亲切的问候
推荐答案
有在这个DotNetNuke的code <一个例子href=\"https://dotnetnuke.svn.$c$cplex.com/svn/trunk/Community/DotNetNuke.Web/InternalServices/FileUploadController.cs\">here (请参阅 PostFile()
法)。
There is an example in this DotNetNuke Code here (See the PostFile()
method).
更新基于@FilipW评论...
Updated based on @FilipW comment...
获得您需要的内容项,然后访问FileName属性。
Get the content item you require and then access the filename property.
事情是这样的:
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);
}
}
这篇关于MultipartMemoryStreamProvider:文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!