我希望通过Evernote API进行附件。
此处的网页:
https://dev.evernote.com/doc/articles/creating_notes.php#
有一个用于创建附件的部分,但这两个代码示例不正确(它们是createNote示例),它们只是Python和Objective-C。
是否有如何使用Evernote JavaScript API作为附件的示例?
答案 0 :(得分:0)
以下是创建仅包含png文件的注释的示例代码:
import {Evernote} from 'evernote';
import md5 from 'md5'
// I have a base64 encoded file, convert to Buffer
const binaryResource = new Buffer(fileData, 'base64');
const fileMime = 'img/png'; // or whatever your mime type is
const fileName = 'testImage.png'; // or whatever your mime type is
const md5Hash = md5(binaryResource);
const resourceAttributes = new Evernote.ResourceAttributes({
fileName: fileName,
});
const resource = new Evernote.Resource({
data: new Evernote.Data({body: binaryResource}),
mime: fileMime,
attributes: resourceAttributes,
});
const content = ''
+ '<?xml version="1.0" encoding="UTF-8"?>'
+ '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
+ '<en-note>'
+ ' <en-media type="' + fileMime + '" hash="' + md5Hash + '"/>'
+ '</en-note>';
const n = new Evernote.Note({
title: fileName,
content: content,
resources: [resource],
});
const evernoteClient = new Evernote.Client({
token: authToken,
sandbox: false, // true for sandbox testing
});
evernoteClient.getNoteStore().createNote(n, (err, res) => {
if (err) {
console.log('Error creating note: ' + err);
} else {
console.log('Created note: ', res);
}
});