I'm testing the self hosted parse-server-example and I want to request an image and save it on my server file system. My code so far:
Parse.Cloud.define('getImage', function(request, response) {
var fs = require('fs');
var testURL = 'http://example.com/test.jpg';
Parse.Cloud.httpRequest({
url: testURL,
method: 'GET',
success: function(httpResponse) {
var imageBuffer = httpResponse.buffer;
fs.writeFile("/mypath/processed.jpg", imageBuffer, function() {
console.log('Saved to disk');
});
response.success('Saved image');
},
error: function(httpResponse) {
response.error('Error getting image');
}
});
});
Problem: A file is created but is nearly doubled in size and can't be opened as an image file. It seems that httpResponse.buffer is returning gibberish.
I also tested to pass imageBuffer.toString('base64') as a parameter to writeFile but had no success. I think its just a simple misunderstanding on my side on how to process the image buffer to write it as a jpg file. Can somebody help or direct me to a working example?