title: evernote nodejs sdk creating note with image
body: <p>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.</p>
  <p>Here is what I have tried.</p>
  <p>Starting with the demo from evernote sdk <a href="https://github.com/evernote/evernote-sdk-js" rel="nofollow noreferrer">https://github.com/evernote/evernote-sdk-js</a> I modified the express sample to create a new note.</p>
  <p>Here is the method to create a resource from an image:</p>
  <pre><code>const crypto = require('node:crypto');
  const Evernote = require('evernote');
  const fs = require('fs');
  
  function createResource(filename) {
    return new Promise((resolve, reject) =&gt; {
      fs.readFile(filename, (err, image) =&gt; {
        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);
        }
      });
    });
  }
  </code></pre>
  <p>Which I then use is the following method to create the note:</p>
  <pre><code>function makeNote(noteStore, noteTitle, noteBody, parentNotebook, resources) {
    var nBody = '&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;';
    nBody += '&lt;!DOCTYPE en-note SYSTEM &quot;http://xml.evernote.com/pub/enml2.dtd&quot;&gt;';
    nBody += '&lt;en-note&gt;' + noteBody + '&lt;/en-note&gt;';
  
    // Create note object
    var ourNote = new Evernote.Types.Note();
    ourNote.title = noteTitle;
    ourNote.content = nBody;
  
    if (resources &amp;&amp; resources.length &gt; 0) {
      // Add Resource objects to note body
      nBody += '&lt;br /&gt;&lt;br /&gt;';
      ourNote.resources = resources;
      for (var i in resources) {
        nBody += 'Attachment with hash: &lt;br /&gt;&lt;en-media type=&quot;' + resources[i].mime + '&quot; hash=&quot;' + resources[i].data.bodyHash + '&quot; width=&quot;200&quot; height=&quot;200&quot; /&gt;&lt;br /&gt;';
      }
    }
  
    // parentNotebook is optional; if omitted, default notebook is used
    if (parentNotebook &amp;&amp; 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);
      });
  }
  </code></pre>
  <p>I tried to see this link in the evernote doc here (create node with attachment section)</p>
  <p><a href="https://dev.evernote.com/doc/articles/creating_notes.php" rel="nofollow noreferrer">https://dev.evernote.com/doc/articles/creating_notes.php</a></p>
  <p>but unfortunately the doc is wrong and the code does not refer to the creating a resource section as it mentions.</p>
  <p>The result is I see the new note and the image in the thumbnail but not in the note itself</p>
  <p><a href="https://i.stack.imgur.com/a8ysd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a8ysd.png" alt="enter image description here" /></a></p>