Created
January 7, 2019 20:36
-
-
Save tnajdek/4ad304b1b9ba0bc3b51cdfc136f7f66a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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