From 383211025e69ac7256aea7c873b074c5dbcf978a Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Tue, 30 Jul 2024 16:17:15 +0200 Subject: [PATCH] WIP --- src/kinto_http/client.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/kinto_http/client.py b/src/kinto_http/client.py index 10d1cd9..d993510 100644 --- a/src/kinto_http/client.py +++ b/src/kinto_http/client.py @@ -861,6 +861,35 @@ def purge_history(self, *, bucket=None, safe=True, if_match=None) -> List[Dict]: resp, _ = self.session.request("delete", endpoint, headers=headers) return resp["data"] + @retry_timeout + def add_attachment(self, record=None, bucket=None, collection=None): + filename = os.path.basename(filepath) + filecontent = open(filepath, "rb").read() + mimetype, _ = mimetypes.guess_type(filepath) + multipart = [("attachment", (filename, filecontent, mimetype))] + + endpoint = self._get_endpoint("attachment", id=id, bucket=bucket, collection=collection, permissions=None, data=None) + resp = requests.post( + endpoint, + data={ + "data": json.dumps(data), + "permissions": json.dumps(permissions), + }, + files=multipart, + headers={"Authorization": AUTHZ} + ) + resp.raise_for_status() + + @retry_timeout + def remove_attachment(self, ): + endpoint = self._get_endpoint("attachment", id=id, bucket=bucket, collection=collection, permissions=None, data=None) + requests.delete( + endpoint, + headers={"Authorization": AUTHZ} + ) + resp.raise_for_status() + + def __repr__(self) -> str: if self.collection_name: endpoint = self._get_endpoint(