Reputation: 867
I got base64 object from canvas
var imageData = canvas.toDataURL('image/png');
And I try to send this base64 object (imageData) to server via ajax:
var _data = {};
// set test property:
_data.avatar = imageData;
console.log(_data);
// Make an Ajax request
$.post('./setup', _data, function(result) {
console.log('result', result);
});
In my nodejs server (using only express midleware), I got a simple router to process this request
router.post('/setup', function(req, res, next) {
console.log('setup: data', req.body.data);
console.log('setup: check', req.body.check);
console.log('setup avatar: ', req.body.avatar);
res.json({
success:true
});
});
Actually, it is not working and I wonder why the base64 object cannot be sent. In another cases my json object with text inside can send to server nomally.. Thank for your help and solution to send base64 object to expressjs server
Upvotes: 2
Views: 4196
Reputation: 1594
Try to increase the limit of data your body parser can handle like:
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
Upvotes: 5