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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Mime types of attachments uploaded to Trello

I'm attempting to upload MP3 attachments to a Trello card (using the API, with the Python Trello module). I'm taking care to make sure the mimeType is set to 'audio/mpeg3', and that the file is encoded as multipart/form-data.

The upload itself happens fine, and the response data shows that Trello thinks it's a MIME type of 'audio/mpeg3' as I specified.

However, looking at the card, the attachment doesn't appear as an MP3, just a generic link, meaning that when clicking on the attachment in the card, it thinks I want to download it (i.e. a generic file) rather than listen to it.

Can anyone explain what's happening here?

4 answers

1 vote
Iain Dooley Community Leader May 05, 2020

@Adrian Sutton yep I've never been able to get Trello uploads to work via the API the same way they do if you upload via the app. What I concluded is that, internally, all attachments are just links and there's something that happens in the Trello interface to set "isUpload" to true and set the mimetype so the icon is displayed differently on the card, but that never happens in the API.

Are there any devs from Atlassian here that can explain why this happens?..

I've just noticed that this issue happens only for certain mime types. For instance image files (such as "image/jpeg") work as expected, but neither MP3s nor PDFs do.
Also, note that mp3s uploaded via the GUI result as "audio/mp3" (via the get card attachments endpoint). And unfortunately no, it doesn't work even by "patching" the mime type in this way before posting  :(

Ok, I think I've figured out the issue. Here's a snippet of the body multi-part data generated by the trello.com website when adding attachments:

------WebKitFormBoundaryMpa8IFEcwGeZ3C67
Content-Disposition: form-data; name="token"

5360ecf0889ea2ef01811bc2/bIZEBmZCuwzhyYVrj75WEpC21t1lebRyWKRZgdjLWBZuBg4H92rpWqqthVuvDVdG
------WebKitFormBoundaryMpa8IFEcwGeZ3C67
Content-Disposition: form-data; name="file"; filename="funky-phone.mp3"
Content-Type: audio/mpeg


------WebKitFormBoundaryMpa8IFEcwGeZ3C67--

Not all http client libs include the "filename" entry. By manually adding it the attachment mime-type seems correct.
For example, in PHP with Guzzle you need to explicitly add a "filename" attribute within the request:

'multipart' => [ 
[
'name' => 'name', 'contents' => $file->getName() ],
[
'name' => 'token', 'contents' => $this::$trelloToken ],
[ 'name' => 'file', 'contents' => $file->fopen('rb'), 'filename'=>$file->getName() ]
]


Hope this helps.

Like Iain Dooley likes this
Iain Dooley Community Leader May 19, 2020

@Fabio Barbon awesome! Keen to give this a try

Thanks Fabio, will try

Hey @Fabio Barbon !

How has the progress on this been? I'm using python and am not at all familiar with PHP. I was wondering if there's any way to apply your solution using a library such as requests, or if you could translate your solution into a curl request? Any help would be appreciated.

Thanks for looking into this!

I've tried to pass the 'filename' attribute as a param to the request and also as a data key:

async def attach_card(self, card_id: str, file_bytes, file_name, mime):
  data = {'file': file_bytes, 'filename': file_name} // here
  headers = {"Accept": "application/json"}
  params = {'name': file_name, 'mimeType': mime, 'filename': file_name} // and here
  params.update(BASE_PARAMS)

  await self.session.post(
    f"{BASE_URL}/cards/{card_id}/attachments",
    params=params,
    data=data,
    headers=headers
)

Neither works :(

Here's what I got to work in the end (this is a method in a class handling everything related to Trello in my application, self._apikey and self._token are the REST credentials etc.)

 

def attachFileToCardID(self, trelloCardID, theFile, theName, theMIMEtype):
resp = requests.post("https://trello.com/1/cards/{}/attachments".format(trelloCardID),
params={'key': self._apikey, 'token': self._token},
files={'file': (theName, open(theFile, 'rb'), theMIMEtype)})
attachmentID = json.loads(resp.text)
return attachmentID 

[object Object]

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Trello

📹 What is Trello?

Hello Community!  My name is Brittany Joiner and I am a Trello enthusiast and Atlassian Community Leader. I'll be sharing with you a series of videos with my top tips on how to best use Trello...

817 views 13 30
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you