Skip to content

Instantly share code, notes, and snippets.

@bensquire
Last active April 28, 2022 12:14
Show Gist options
  • Save bensquire/22ef6a439563d1bab6611ee07cc78827 to your computer and use it in GitHub Desktop.
Save bensquire/22ef6a439563d1bab6611ee07cc78827 to your computer and use it in GitHub Desktop.
Trello API Card Attachment using formdata-node and axios (NodeJS)
// Note, axios isn't a formData spec compliant client, hence the need for formdata-node encoder
import {Readable} from "stream"
import axios from 'axios';
import {FormData} from "formdata-node"
import {fileFromPath} from "formdata-node/file-from-path"
import {FormDataEncoder} from "form-data-encoder"
const cardId = 'REPLACE'
const file = './354.jpg'
const form = new FormData()
form.set('file', await fileFromPath(file))
const encoder = new FormDataEncoder(form)
await axios.post(
`https://api.trello.com/1/cards/${cardId}/attachments`,
Readable.from(encoder),
{
headers: encoder.headers,
params: {
key: 'REPLACE',
token: 'REPLACE'
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment