1
我试图从服务上传文件到控制器。我检查,该文件是在服务上,但我不能把它传递给控制器
uploadFile = function (file) {
var promise = $http(
{
method: 'POST',
withCredentials: true,
url: self.baseUrl + 'Admin/uploadFile',
contentType: 'undefined',
data: {
file: file
}
});
return promise;
}
[HttpPost]
public ActionResult uploadFile()
{
try
{
var file = Request.Files[0];
Response.StatusCode = 200;
return Content("updated");
}
catch (Exception ex)
{
Response.StatusCode = 500;
return Content("Fail");
}
}
所以,你的问题实际上是“如何从angularjs前端上传文件[您使用的后端式技术]”,对不对?提及您使用的标签中的后端技术会很有帮助。 –
这是asp.net MVC ...你可以从代码中知道。我想你可能需要使用headers对象来为你的$ http请求设置标题(例如 - '''headers:{'Content-Type':undefined}'''而不是你拥有它的方式 – bri
谢谢。当我插入:标题:{'Content-Type':undefined}我得到404错误 – user6934713