Vote count:
0
I sent a $http.post
request from Angular.js to Node.js in order to get an ArrayBuffer
as following:
$http.post('/api/scholarships/load/uploaded-files', Global.user, {responseType:'arraybuffer'}).success(function(ab){
console.log(ab); // Return ArrayBuffer {}
});
Then, in Node.js, I retrieved uploaded files data and transform a Buffer
object to ArrayBuffer
object:
exports.loadUploadedFiles = function(req, res) {
db.UserFile.findAll().success(function(files) {
var buffer = files[0].dataValues.data; // Get buffer
var arrayBuffer = new ArrayBuffer(buffer.length); // Start transforming Buffer to ArrayBuffer
var views = new Uint8Array(arrayBuffer);
for(var i = 0; i < buffer.length; ++i) {
views[i] = buffer[i];
}
res.type('arraybuffer');
res.send(arrayBuffer);
}).error(function(err) {
console.log(err);
res.sendStatus(500);
});
};
When I tried to print the response from above $http.post
, I always got ArrayBuffer{}
. What did I do wrong? Any help would be appreciated.
asked 54 secs ago
How to return ArrayBuffer from $http request in Node.js?
Aucun commentaire:
Enregistrer un commentaire