From 23726bb41761e2f6a15148065c452fc5fcfbc559 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 5 Sep 2022 23:05:54 +0100 Subject: [PATCH 1/2] add update attachment --- Bookstack.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Bookstack.py b/Bookstack.py index e8825a4..4e64655 100644 --- a/Bookstack.py +++ b/Bookstack.py @@ -62,6 +62,23 @@ def get_attachment(wiki_url, token_id, token_secret, attachment_id): return attachment_data_decoded +def update_attachment(wiki_url, token_id, token_secret, attachment_id, file_name, file_data, page_id): + headers = {} + headers.update(get_auth_header(token_id, token_secret)) + + data = {} + # Workaround for updating files: https://github.com/BookStackApp/BookStack/issues/3666 + data["_method"] = "PUT" + data["name"] = file_name + data["uploaded_to"] = page_id + + files = {} + files["file"] = file_data + + requests.post(wiki_url + "/api/attachments/{}".format(attachment_id), headers=headers, data=data, files=files) + + + def delete_attachment(wiki_url, token_id, token_secret, attachment_id): headers = {} headers.update(get_auth_header(token_id, token_secret)) From 2a1d0b9c186d25c44f7299924f4b8b3b71cbcab7 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 5 Sep 2022 23:07:29 +0100 Subject: [PATCH 2/2] remove newline --- Bookstack.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Bookstack.py b/Bookstack.py index 4e64655..b650437 100644 --- a/Bookstack.py +++ b/Bookstack.py @@ -78,7 +78,6 @@ def update_attachment(wiki_url, token_id, token_secret, attachment_id, file_name requests.post(wiki_url + "/api/attachments/{}".format(attachment_id), headers=headers, data=data, files=files) - def delete_attachment(wiki_url, token_id, token_secret, attachment_id): headers = {} headers.update(get_auth_header(token_id, token_secret))