1 # Upload a file attachment to a BookStack page
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.
7 This is a simplistic example of a Python script. You will likely want to
8 alter and extend this script to suit your use-case.
10 This was written without in-depth knowledge of Python nor experience
11 of Python common conventions, so the style and approaches may appear unconventional.
15 You will need Python 3 installed (3.10.7).
16 This also uses pip to import requests as a dependency.
20 First, download all the files in the same directory as this readme to a folder on your system
21 and run the below from within that directory.
24 # Install dependencies via PIP
25 pip install -r requirements.txt
28 # ALTERNATIVELY: Open the script and add to the empty strings in the variables at the top.
29 export BS_URL=https://bookstack.example.com # Set to be your BookStack base URL
30 export BS_TOKEN_ID=abc123 # Set to be your API token_id
31 export BS_TOKEN_SECRET=123abc # Set to be your API token_secret
34 python main.py <page_id> <file_path>
37 - `<page_id>` - The ID of the page you want to upload the attachment to.
38 - `<file_path>` - File you want to upload as an attachment.
43 # Upload the 'cat-image-collection.zip' file as an attachment to page of ID 205
44 python main.py 205 ./cat-image-collection.zip