使用Web API2上传文件作为正文的一部分 [英] upload a file as part of the Body with Web API2

查看:257
本文介绍了使用Web API2上传文件作为正文的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建WebAPI POST请求,获取主体并将其保存在数据库中。
其中一个字段是一个 文件 ,可以是图片,pdf,...



我应该创建一个异步发布请求并将文件发布到那个?
这是我找到的样本。
http ://www.codeguru.com/csharp/.net/uploading-files-asynchronously-using-asp.net-web-api.htm

解决方案

您可以尝试使用'HttpPostedFileBase'类将该文件作为Http请求主体的一部分发布。
类似于这样:

pre $ $ $ b $ public ActionResult UploadFile($ H $ $ $ $ $ $ $ $ $ $ $ $) {
//您的API代码
}


I want to create WebAPI POST request which gets the body and save it in Database. One of the body's fields is a file, which can be the image, 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

解决方案

You can try using 'HttpPostedFileBase' class to post the file as part of the Http request Body. Something like this:

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

这篇关于使用Web API2上传文件作为正文的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆