api-scripts/node-upload-attachment
2022-02-05 06:35:15 +00:00
..
index.js Added node-based file attachment upload example 2022-02-05 06:35:15 +00:00
package-lock.json Added node-based file attachment upload example 2022-02-05 06:35:15 +00:00
package.json Added node-based file attachment upload example 2022-02-05 06:35:15 +00:00
readme.md Added node-based file attachment upload example 2022-02-05 06:35:15 +00:00

Upload a file attachment to a BookStack page

This script will take a path to any local file and attempt to upload it to a BookStack page as an attachment using the API using a multipart/form-data request.

This is a simplistic example of a NodeJS script. You will likely want to alter and extend this script to suit your use-case.

Requirements

You will need NodeJS installed (Tested on v16, may work on earlier versions).

Running

First, download all the files in the same directory as this readme to a folder on your system and run the below from within that directory.

# Install NodeJS dependencies via NPM
npm install 

# Setup
# ALTERNATIVELY: Open the script and add to the empty strings in the variables at the top.
export BS_URL=https://bookstack.example.com # Set to be your BookStack base URL
export BS_TOKEN_ID=abc123 # Set to be your API token_id
export BS_TOKEN_SECRET=123abc # Set to be your API token_secret

# Running the script
node index.js <page_id> <file_path>
  • <page_id> - The ID of the page you want to upload the attachment to.
  • <file_path> - File you want to upload as an attachment.

Examples

# Upload the 'cat-image-collection.zip' file as an attachment to page of ID 205
node index.js 205 ./cat-image-collection.zip