]> BookStack Code Mirror - api-scripts/blob - python-upload-attachment/readme.md
Added bsfs to community project list
[api-scripts] / python-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 Python script. You will likely want to
8 alter and extend this script to suit your use-case.
9
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.
12
13 ## Requirements
14
15 You will need Python 3 installed (3.10.7).
16 This also uses pip to import requests as a dependency. 
17
18 ## Running
19
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.
22
23 ```bash
24 # Install dependencies via PIP
25 pip install -r requirements.txt
26
27 # Setup
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
32
33 # Running the script
34 python main.py <page_id> <file_path>
35 ```
36
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.
39         
40 ## Examples
41
42 ```bash
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
45 ```
Morty Proxy This is a proxified and sanitized view of the page, visit original site.