add get_attachment_contents

This commit is contained in:
Sarah 2022-02-19 00:19:31 +00:00
parent a23d9e6d2e
commit b9e2b5bad9
1 changed files with 12 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import base64
import json import json
import requests import requests
@ -34,3 +35,14 @@ def get_attachment_id(attachment_name, page_id, wiki_url, token_id, token_secret
return attachment['id'] return attachment['id']
return None return None
def get_attachment_contents(attachment_id, wiki_url, token_id, token_secret):
headers = {}
headers.update(get_auth_header(token_id, token_secret))
r = requests.get(wiki_url + "/api/attachments/{}".format(attachment_id), headers=headers)
attachment_data_encoded = json.loads(r.text)['content']
attachment_data_decoded = base64.b64decode(attachment_data_encoded)
return attachment_data_decoded