Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to correctly set filename (not name) of card attachments via the Trello REST API

Celine Hernia
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 19, 2022

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!

1 answer

0 votes
Adam Cao
Atlassian Partner
October 19, 2022

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 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events