2

getResourceDataNode.jsを使ってJavaScriptコードで、Evernote方式で受信した画像データをローカルシステムに書き込もうとしています。画像ファイルは正常に保存されていますが、破損しているようで、開くことができません。

この関数getResourceDataは、指定された GUID を持つリソースのバイナリ データを返します。たとえば、これが画像リソースである場合、これには画像の生のビットが含まれます。

コードは次のとおりです。

クライアント.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 };
  });
}

どんな助けでも大歓迎です。

-ペトロ

4

0 に答える 0