我发送从Android客户端到web api的多部分请求它正在接收文件和值,但我需要将文件类型转换为HttpPostedFileBase我已经研究了很多,但他们都没有得到答案这是可能的让我发布我到目前为止所尝试的代码:
[HttpPost]
[Route("~/api/inoteupload")]
public async System.Threading.Tasks.Task<string> UploadFiles()
{
int iUploadedCnt = 0;
try
{
// DEFINE THE PATH WHERE WE WANT TO SAVE THE FILES.
string sPath = @"D:\sfuploads";
sPath = System.Web.Hosting.HostingEnvironment.MapPath("~/");
MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(sPath);
MultipartFileStreamProvider multipartFileStreamProvider = await Request.Content.ReadAsMultipartAsync(streamProvider);
String userid=streamProvider.FormData["userid"];
String date = streamProvider.FormData["date"];
String type = streamProvider.FormData["type"];
HttpPostedFileBase hpf = null;
UploadManager objUploadManager = new UploadManager(UploadTarget.INote, UploadFolder.Original);
UploadFileInfo objUploadFileInfo = objUploadManager.Upload(hpf);
iUploadedCnt = 1;
}
catch(Exception ex)
{
ex.ToString();
iUploadedCnt = 0;
}
// RETURN A MESSAGE (OPTIONAL).
if (iUploadedCnt > 0)
{
return iUploadedCnt + " Files Uploaded Successfully";
}
else {
return "Upload Failed";
}
}