我正在尝试使用一组字段的现有集合。
但是我在 Angular Controller端
获得了以下异常:Possibly unhandled rejection: {
"data":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot POST /image/upload</pre>\n</body>\n</html>\n",
"status":404,
"config":{
"method":"POST",
"transformResponse":[null],
"jsonpCallbackParam":"callback",
"url":"/image/upload",
"headers":{"Accept":"application/json, text/plain, */*"},
"data":{
"model":{"title":"hello"},
"files":[{}]
}
},
"statusText":"Not Found"
}
角色代码:
$http({
method: 'PUT',
url: properties.imageUpload,
headers: { 'Content-Type': undefined },
transformRequest: function(data) {
var formData = new FormData();
formData.append("proId", $scope.pid);
formData.append('model', angular.toJson(data.model));
for (var i = 0; i < data.files.length; i++) {
formData.append('file', data.files[i]);
$scope.uploadedFiles.push(data.files[i]);
}
console.log('Sending File size :' + data.files.length);
//formData.append('file', data.files[0]);
return formData;
},
data: { model: { title: 'hello' }, files: $scope.files }
}).then(function(res) {
$scope.selectedFiles = "/public/images/" + res.data.imagePaths[0];
// console.log(res.data.imagePaths[0]);
});
$scope.addProducts = function () {
var product = $scope.product;
$http.post('/products/create', $scope.product).then(function (res) {
console.log(res.data._id);
$scope.upload(res.data._id);//this contains put request.
});
}
请帮忙。