我想從我的客戶端(AngularJs)向我的NodeJs服務器發送一個base64字符串數組。 我遇到了一個奇怪的情況。每當我送的物體,像這樣:Angular JS向BaseJs服務器發送base64陣列 - Allow-Access-Control-Origin
{Price: 1000000, LookingFor: "Rent", RoomsNumber: 4, Area: 1000, PropertyType: "Any", Base64:['data:image/jpeg;base64,/9..'] }
我得到一個錯誤這樣的:
XMLHttpRequest cannot load http://localhost:8080/estate. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 413.
當我刪除的base64 HTTP請求正在工作。另外,當我只向服務器發送一個base 64字符串時,服務器接受它。
在客戶端,我採用了棱角分明的$ HTTP:
self.PostEstate = function (estate) {
console.log(serverLocation + 'estate');
console.log('sending estate', estate);
$http.post(serverLocation + 'estate', estate)
.success(function (data) {
console.log('successfully sent estate', data);
$rootScope.$broadcast('postEstate', {
IsSucceded: true,
_id: data
})
}).error(function (err) {
$rootScope.$broadcast('postEstate', {
Msg: err,
IsSucceded: false
})
});
}
而且在我的服務器我使用我的應用程序的簡單的路由:
app.post('/estate', function (req, res) {
var estate = new Estate({
Price: req.body.Price,
LookingFor: req.body.LookingFor,
RoomsNumber: req.body.RoomsNumber,
Area: req.body.Area,
PropertyType: req.body.PropertyType,
Desc: req.body.Desc,
photos: []
});
//Thats mongoose obj
estate.save(function (err) {
if (err)
res.send(err);
res.json({
_id: estate._id
});
});
});
我想,發佈請求太大,我可以刪除限制嗎? 如果不是,你能建議另一個架構,我可以發送base64陣列到我的服務器? 預先感謝您。 PS只是提到他我使用節點10與快遞4.
是否有任何理由你不使用'多/形式 - 數據'上傳圖片? – m90