forked from bunqCommunity/bunqJSClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_upload.js
More file actions
33 lines (27 loc) · 1.27 KB
/
file_upload.js
File metadata and controls
33 lines (27 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require("dotenv").config();
const fs = require("fs");
const path = require("path");
const setup = require("./common/setup");
setup()
.then(async BunqClient => {
// get the image contents
const file = fs.readFileSync(`${__dirname}${path.sep}common${path.sep}Ali-Niknam-50x50.jpg`);
// attempt to upload the file
const imageUuid = await BunqClient.api.attachmentPublic.post(file, "image/jpeg");
console.log("Image UUID", imageUuid, "\n");
// fetch the image contents of the newly updated image
const imageContents = await BunqClient.api.attachmentContent.get(imageUuid, { base64: false });
console.log("Image private contents\n", imageContents, "\n");
// write to dist folder to prevent git inclusion, check the results there
fs.writeFileSync(`${__dirname}${path.sep}..${path.sep}Ali-Niknam-50x50-private-result.jpg`, imageContents);
// post the imageUuid to turn it into a public avatar
const avatarUuid = await BunqClient.api.avatar.post(imageUuid);
console.log("Public avatar UUID", avatarUuid, "\n");
})
.catch(error => {
console.log(error);
if (error.response) {
console.log(error.response.data);
}
})
.finally(() => process.exit());