Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

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.

share|improve this question

closed as off topic by phwd Aug 27 '12 at 19:01

Questions on Web Applications Stack Exchange are expected to relate to web applications within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

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
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

1 Answer 1

up vote 1 down vote accepted

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)

share|improve this answer
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 2 days ago

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