in remote_settings/client.py [0:0]
def attach_file_to_record(self, index):
"""Attaches the file attachment to the record of the matching id.
Args:
index (int): The index of the record.
Raises:
KintoException: An exception if the record was not able to be uploaded.
"""
headers = {"Authorization": f"Bearer {self._auth_token}"}
attachment_endpoint = "buckets/{}/collections/{}/records/{}/attachment".format(
BUCKET, COLLECTION, self._new_records[index]["id"]
)
response = requests.post(
f"{self.server_url()}{attachment_endpoint}",
files=[
(
"attachment",
(
self.attachment_name(index),
self.attachment_content(index),
self.attachment_mimetype(index),
),
)
],
headers=headers,
)
if response.status_code > 200:
raise KintoException(
f"Couldn't attach file at endpoint {self.sever_url()}{attachment_endpoint}: "
+ f"{response.content.decode('utf-8')}"
)