Skip to content

Commit 3d822eb

Browse files
committed
Added example file upload script
refs https://github.com/TryGhost/Toolbox/issues/219 - Example on how to use the "files.upload" method exposed through Admin API SDK / Admin API.
1 parent 6ac272d commit 3d822eb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

upload-file.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Warning: This script uses an experimental alpha feature
3+
*
4+
* Upload a local media file
5+
*
6+
* To run me:
7+
*
8+
* 1. Replace "YOUR_ADMIN_API_KEY" below with your admin key (and edit the URL if you're not using localhost)
9+
* 2. Make sure the example you want to test is uncommented
10+
* 3. Run `node upload-file.js ./sample_document.pdf some-ID-123`
11+
* ^ script name ^ path to file ^ reference
12+
*/
13+
14+
// The admin API client is the easiest way to use the API
15+
const GhostAdminAPI = require('@tryghost/admin-api');
16+
const path = require('path');
17+
18+
// Configure the client
19+
const api = new GhostAdminAPI({
20+
url: 'http://localhost:2368',
21+
// @TODO: edit your key here
22+
key: 'YOUR_ADMIN_API_KEY_HERE',
23+
version: 'canary'
24+
});
25+
26+
const file = process.argv[2];
27+
const ref = process.argv[3];
28+
29+
api.files.upload({
30+
file: path.join(__dirname, file),
31+
ref
32+
})
33+
.then(response => console.log(response))
34+
.catch(error => console.error(error));

0 commit comments

Comments
 (0)