Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Jul 30, 2024
1 parent d1f8650 commit 3832110
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/kinto_http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3832110

Please sign in to comment.