The file parameter documentation for the POST /1/cards/[card id or shortlink]/attachments API call does not specify how the file should be encoded. For "Valid Values" it simply says "A file". I was wondering if anyone has a working example of how to get files into Trello cards using the API.

  • Trello uses that API to attach files, so you should be able to use it as an example. (i.e. you can look at the Network tab in Chrome after attaching a file) – Daniel LeCheminant Aug 27 '12 at 17:50
  • 1
    API questions are off-topic here, it might work on Stack Overflow but be sure to show prior work in the form of code – phwd Aug 27 '12 at 19:02

You should be able to add an attachment using the multipart/form-data content type:

<form action="https://api.trello.com/1/cards/REPLACE_WITH_CARD_ID/attachments"
      method="POST" enctype="multipart/form-data">
   <input type="hidden" name="key" value="REPLACE_WITH_YOUR_KEY" />
   <input type="hidden" name="token" value="REPLACE_WITH_YOUR_WRITE_TOKEN" />
   <input type="file" name="file">
   <input type="submit" value="Upload">

(You don't necessarily have to be POSTing from a webpage, but that's an easy example)

| improve this answer | |
  • 1
    If I'm not using HTML forms can I just set the value of the file parameter in the post to a Base64 encoded file? Or will I somehow need to convert that into multipart/form-data? Sorry if I'm being stupid. – Jack Jones Aug 27 '12 at 18:21
  • The library we're using to handle forms doesn't yet support base64 – Daniel LeCheminant Aug 27 '12 at 18:58
  • @JackJones Did you manage to upload a file the way you wanted? Were you trying to actually accept a file upload from the user, or some pure-javascript trick? I'm looking for solutions for uploading strings as files for my Trello Attachment Editor, since to this day it is using the browser File API, which is only supported in Chrome and Firefox. – fiatjaf Sep 1 '15 at 20:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.