i am posting binary image data to nodejs and receiving it using the following code concept
var requestBody = '';
this.request.on('data', function (data) {
requestBody += data;
if (requestBody.length > 1e6 * config.POST_MAX_SIZE) {
// FLOOD ATTACK OR FAULTY CLIENT, NUKE REQUEST
this.request.connection.destroy();
}
});
this.request.on('end', function () {
this.post = qs.parse(requestBody);
});
because i concat the data as string i get the image data as a string representation in the form of:
<ffd8ffe0 00104a46 49460001 01000048 00480000 ffe10058 45786966 00004d4d 002a0000 00080002 01120003 00000001 00010000 87690004 00000001 ....
now how can i return this data to binary and save it to a file, i have tried this code, its save the image but the image is corrupted:
fs.writeFile("myimage.jpg", new Buffer(this.post.imageData, 'binary') ,function(err){});
when i open the image in a text editor its still in the form
<ffd8ffe0 00104a46 49460001 01000048 00480000 ffe10058 45786966 00004d4d 002a0000 00080002 01120003 00000001 00010000 87690004 00000001 ....
Aucun commentaire:
Enregistrer un commentaire