]> BookStack Code Mirror - api-scripts/blob - node-upload-attachment/readme.md
Added postman collection gen example
[api-scripts] / node-upload-attachment / readme.md
1 # Upload a file attachment to a BookStack page
2
3 This script will take a path to any local file and attempt
4 to upload it to a BookStack page as an attachment
5 using the API using a multipart/form-data request.
6
7 This is a simplistic example of a NodeJS script. You will likely want to
8 alter and extend this script to suit your use-case.
9
10 ## Requirements
11
12 You will need NodeJS installed (Tested on v16, may work on earlier versions). 
13
14 ## Running
15
16 First, download all the files in the same directory as this readme to a folder on your system
17 and run the below from within that directory.
18
19 ```bash
20 # Install NodeJS dependencies via NPM
21 npm install 
22
23 # Setup
24 # ALTERNATIVELY: Open the script and add to the empty strings in the variables at the top.
25 export BS_URL=https://bookstack.example.com # Set to be your BookStack base URL
26 export BS_TOKEN_ID=abc123 # Set to be your API token_id
27 export BS_TOKEN_SECRET=123abc # Set to be your API token_secret
28
29 # Running the script
30 node index.js <page_id> <file_path>
31 ```
32
33 - `<page_id>` - The ID of the page you want to upload the attachment to.
34 - `<file_path>` - File you want to upload as an attachment.
35         
36 ## Examples
37
38 ```bash
39 # Upload the 'cat-image-collection.zip' file as an attachment to page of ID 205
40 node index.js 205 ./cat-image-collection.zip
41 ```