I have a function/method that creates a new attachment, particularly a text file, to a card. It successfully attaches the file to the card but when downloaded locally, the filename is always set to "Upload", not the actual filename "*.txt". Here's my function:
def create_attachment_on_card(self, card_id, filename):
"""
creates a file attachment on a card
"""
url = f"https://api.trello.com/1/cards/{card_id}/attachments"
with open(f'dataset/{filename}.txt', 'rb') as file:
content = file.read()
query = {
'key': self.key,
'token': self.token,
'name': f'{filename}.txt',
'file': content,
'mimeType': 'text/plain'
}
response = requests.request(
"POST",
url,
headers=self.std_headers,
params=query
)
return response.status_code
I would greatly appreciate any input on this. Thank you!
I would recommend setting the filename field in your multipart/form-data payload that you send to Trello when you upload the attachment (i.e. your other function).
See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.