I am trying to write image data received from Evernote getResourceData
-method, into local system in JavaScript code using Node.js. The image file is getting saved successfully, but looks like it is corrupted, and I'm not able to open it.
The function getResourceData
returns binary data of the resource with the provided GUID. For example, if this were an image resource, this would contain the raw bits of the image.
- Hex of original: http://i41.tinypic.com/ev8bnr.jpg
- Hex of downloaded: http://i41.tinypic.com/10rs7zm.jpg
Here's the code:
Client.js:
var onSuccess = function(resource, transport) {
self.showResourceData(resource);
//console.log("Got Resource: "+resource);
};
NoteStore.getResourceData(onSuccess,this.showAlertMessage.bind(this,
"Failed to get Resource"), inSender.getValue());
showResourceData: function(resource) {
//Calls WriteFileAssistant service
this.$.writeFile.call({ path: "/downloads/logo1.png", content: resource });
}
WriteFileAssistant.js:
WriteFileAssistant.prototype.run = function(future) {
var filePath = this.controller.args.path;
var content = this.controller.args.content;
var downloadfile = fs.createWriteStream(filePath,
{'flags': 'w', encoding: 'binary'});
downloadfile.write(content, encoding='binary', function(err) {
future.result = { path: filePath, bytes: content.length, error: err };
});
}
Any help will be greatly appreciated.
-Petro