简体   繁体   English

使用Web API2上传文件作为正文的一部分

[英]upload a file as part of the Body with Web API2

I want to create WebAPI POST request which gets the body and save it in Database. 我想创建获取正文的WebAPI POST请求并将其保存在数据库中。 One of the body's fields is a file , which can be the image, pdf, ... 身体的一个字段是file ,可以是图像,pdf,...

should I create a Async Post request and post the file to that? 我应该创建一个异步发布请求并将文件发布到该请求吗? This is the sample I found for that. 这是我为此找到的样本。 http://www.codeguru.com/csharp/.net/uploading-files-asynchronously-using-asp.net-web-api.htm http://www.codeguru.com/csharp/.net/uploading-files-asynchronously-using-asp.net-web-api.htm

You can try using 'HttpPostedFileBase' class to post the file as part of the Http request Body. 您可以尝试使用“ HttpPostedFileBase”类将文件发布为Http请求主体的一部分。 Something like this: 像这样:

[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase file)
{
  // you API code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM