Last active
April 28, 2022 12:14
-
-
Save bensquire/22ef6a439563d1bab6611ee07cc78827 to your computer and use it in GitHub Desktop.
Trello API Card Attachment using formdata-node and axios (NodeJS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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