我尝试上传文件并希望将上传文件数据发送到C#后端。有了这段代码:
HTML
<input type="file" id="upload" name="file" onchange="angular.element(this).scope().uploadedFile(this)" multiple />
AngularJS Serivce
uploadfile: function (files, type, status) {
var route = 'api/sc/ir/cid/' + $cookies.get("cid") + '/type/' + type + '/status/' + status;
for (var i = 0; i < files.length; i++) {
$http.post(serviceBase + route, files[i], {
withCredentials: false,
transformRequest: angular.identity,
headers: { 'Content-Type': 'application/json' }
})
}
return true;
}
C#Controller
[HttpPost]
[Route("api/sc/ir/cid/{cid:int}/type/{type}/status/{status}")]
[ResponseType(typeof(ValidateModel))]
public IHttpActionResult AddFileRequests(int cid, string type, string status, HttpPostedFileBase file)
{
var newRequest = logic.UploadDocument(clinicId, type, status, file);
return Created(Request.RequestUri.ToString(), newRequest);
}
问题在于&#39;文件&#39;到达后端时,object为null,但它在前端很好地填充了。我错过了什么?