Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,704
Community Members
 
Community Events
184
Community Groups

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

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 19, 2022 • edited

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