Skip to content

Instantly share code, notes, and snippets.

@tnajdek
Created January 7, 2019 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnajdek/4ad304b1b9ba0bc3b51cdfc136f7f66a to your computer and use it in GitHub Desktop.
Save tnajdek/4ad304b1b9ba0bc3b51cdfc136f7f66a to your computer and use it in GitHub Desktop.
const api = require('./src/api');
const fs = require('fs');
const filedata = fs.readFileSync('picture.jpg');
// live api, vexlign credentials
const APIKEY = '';
const USERID = '';
const ITEM_KEY = '';
(async () => {
try {
const template = (await api()
.template('attachment')
.get({ linkMode: 'imported_file' })).getData();
const item = {
...template,
title: 'attached picture',
parentItem: ITEM_KEY,
filename: 'picture.jpg',
contentType: 'image/jpeg',
};
const attachmentItem = (await api(APIKEY)
.library(USERID)
.items()
.post([item])).getEntityByIndex(0);
const response = await api(APIKEY)
.library(USERID)
.items(attachmentItem.key)
.attachment('picture.jpg', filedata.buffer)
.post();
} catch(e) {
// , uploadResponse, registerResponse
console.warn(e, e.reason, e.message, e.options);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment