【发布时间】:2013-01-22 08:25:46
【问题描述】:
我目前正在使用 Web API 开发 REST 网络服务。我在处理通过 POST 请求传输的二进制数据(图像)时遇到了问题。
从客户端的角度来看,我已经设法使用 jQuery 表单插件 发送二进制数据。但是因为我对 .NET 非常陌生(我是一名 PHP 开发人员),所以我很难通过服务器上的 Web API 处理这些二进制数据。
为了确认 jQuery 表单插件正确发送图像数据,我编写了一个使用简单的 $_FILE 全局变量的 PHP 处理程序。
现在我正在尝试通过 Web API 来完成同样的任务。这是我尝试过的概述。如何访问已发送的二进制数据?
型号:
namespace EDHDelivery.Models
{
public class Oferta
{
public int OfertaID { get; set; }
public string Nombre { get; set; }
public string Imagen { get; set; }
public int ComercioID { get; set; }
}
}
控制器(显示部分代码):
public Oferta Add(Oferta item)
{
/*here my item will have the POST body with form values,
automatically serialized by the framework and I think an image binary*/
var n = item.Nombre; //...etc.
}
【问题讨论】:
标签: c# asp.net file-upload asp.net-web-api binary