我與此代碼得到的錯誤是這個REST API代碼有什麼問題?
不能發佈/ IMG /上傳/」
代碼:
app.post('/img/upload/',[multer({ dest: __dirname+'/www/images/new/',
rename: function (fieldname, filename, req, res) {
return filename + '_ORIGINAL';
},
onFileUploadStart: function (file, req, res) {
console.log(file.fieldname + ' is starting ...')
},
onFileUploadData: function (file, data, req, res) {
console.log(data.length + ' of ' + file.fieldname + ' arrived')
},
onFileUploadComplete: function (file, req, res) {
console.log(file.fieldname + ' uploaded to ' + file.path)
},
onError: function (error, next) {
console.log(error)
next(error)
}
})]);
控制器請求這個API是:
var data = new FormData;
data.append("file", files[0]);
$http({
url: 'http://52.25.181.109/img/upload/',
method: "POST",
data : data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data, status, headers, config) {
$scope.hide_u();
console.log(data);
}).error(function (data, status, headers, config) {
$scope.hide_u();
console.log(data);
});
代碼執行錯誤。我該如何糾正?
您是否申請不同的域名? – binariedMe
是所有的錯誤信息說?或者有什麼關於跨域的呢? @RohitKumar建議似乎更可能,因爲您在該網址中使用IP地址。 – NikhilWanpal
這是一個發佈的請求,我正在aws數據庫。其他GET請求工作正常。我遇到問題只爲這個POST請求。 –