add post/delete attachments methods

This commit is contained in:
Sarah 2022-02-25 20:42:59 +00:00
parent e7d3657c5d
commit 50617e94e8
1 changed files with 21 additions and 0 deletions

View File

@ -37,6 +37,20 @@ def get_attachment_id(wiki_url, token_id, token_secret, attachment_name, page_id
return None return None
def post_attachment(wiki_url, token_id, token_secret, filename, filedata, page_id):
headers = {}
headers.update(get_auth_header(token_id, token_secret))
data = {}
data["name"] = filename
data["uploaded_to"] = page_id
files = {}
files["file"] = filedata
requests.post(wiki_url + "/api/attachments", data=data, files=files, headers=headers)
def get_attachment(wiki_url, token_id, token_secret, attachment_id): def get_attachment(wiki_url, token_id, token_secret, attachment_id):
headers = {} headers = {}
headers.update(get_auth_header(token_id, token_secret)) headers.update(get_auth_header(token_id, token_secret))
@ -48,6 +62,13 @@ def get_attachment(wiki_url, token_id, token_secret, attachment_id):
return attachment_data_decoded return attachment_data_decoded
def delete_attachment(wiki_url, token_id, token_secret, attachment_id):
headers = {}
headers.update(get_auth_header(token_id, token_secret))
requests.delete(wiki_url + "/api/attachments/{}".format(attachment_id), headers=headers)
def update_page(wiki_url, token_id, token_secret, page_id, markdown): def update_page(wiki_url, token_id, token_secret, page_id, markdown):
headers = {} headers = {}
headers.update(get_auth_header(token_id, token_secret)) headers.update(get_auth_header(token_id, token_secret))