问题描述
publicclassFileUploadController:ApiController{publicTask<HttpResponseMessage>PostFile(){HttpRequestMessagerequest=this.Request;stringroot=System.Web.HttpContext.Current.Server.MapPath("~/App_Data/uploads");//varprovider=newMultipartFormDataStreamProvider(root);//原写法varprovider=newRenamingMultipartFormDataStreamProvider(root);//重命名写法//provider.BodyPartFileNames.sel(kv=>kv.Value)vartask=request.Content.ReadAsMultipartAsync(provider).ContinueWith<HttpResponseMessage>(o=>{stringfile1=provider.BodyPartFileNames.First().Value;//多张图片循环provider.BodyPartFileNames或provider.FileData //stringfile1=provider.GetLocalFileName(provider.FileData[0].Headers);//返回重写的文件名(注意,由于packages包版本的不同,用BodyPartFileNames还是FileData需要留意)//thisisthefilenameontheserverwherethefilewassavedreturnnewHttpResponseMessage(){Content=newStringContent("Fileuploaded."+file1)};});returntask;}}
解决方案
解决方案二:
分享还是问题?