I am trying to create a note in evernote with an image resource, however the resource only appears as thumbnail in the left as sumbnail but not in the note itself.
Here is what I have tried.
Starting with the demo from evernote sdk https://github.com/evernote/evernote-sdk-js I modified the express sample to create a new note.
Here is the method to create a resource from an image:
const crypto = require('node:crypto');
const Evernote = require('evernote');
const fs = require('fs');
function createResource(filename) {
return new Promise((resolve, reject) => {
fs.readFile(filename, (err, image) => {
if (err) {
reject(err);
} else {
var md5 = crypto.createHash('md5');
var hex = md5.update(image).digest('hex');
var data = new Evernote.Types.Data();
data.bodyHash = hex;
data.body = image;
var resource = new Evernote.Types.Resource();
resource.mime = 'image/jpeg';
resource.data = data;
resource.attributes = new Evernote.Types.ResourceAttributes();
resource.attributes.fileName = filename;
resource.width = 320;
resource.height = 200;
resolve(resource);
}
});
});
}
Which I then use is the following method to create the note:
function makeNote(noteStore, noteTitle, noteBody, parentNotebook, resources) {
var nBody = '<?xml version="1.0" encoding="UTF-8"?>';
nBody += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">';
nBody += '<en-note>' + noteBody + '</en-note>';
// Create note object
var ourNote = new Evernote.Types.Note();
ourNote.title = noteTitle;
ourNote.content = nBody;
if (resources && resources.length > 0) {
// Add Resource objects to note body
nBody += '<br /><br />';
ourNote.resources = resources;
for (var i in resources) {
nBody += 'Attachment with hash: <br /><en-media type="' + resources[i].mime + '" hash="' + resources[i].data.bodyHash + '" width="200" height="200" /><br />';
}
}
// parentNotebook is optional; if omitted, default notebook is used
if (parentNotebook && parentNotebook.guid) {
ourNote.notebookGuid = parentNotebook.guid;
}
// Attempt to create note in Evernote account (returns a Promise)
noteStore.createNote(ourNote)
.then(function(note) {
// Do something with `note`
console.log(note);
}).catch(function(err) {
// Something was wrong with the note data
// See EDAMErrorCode enumeration for error code explanation
// http://dev.evernote.com/documentation/reference/Errors.html#Enum_EDAMErrorCode
console.log(err);
});
}
I tried to see this link in the evernote doc here (create node with attachment section)
https://dev.evernote.com/doc/articles/creating_notes.php
but unfortunately the doc is wrong and the code does not refer to the creating a resource section as it mentions.
The result is I see the new note and the image in the thumbnail but not in the note itself
