Created
March 19, 2020 17:44
-
-
Save steingrd/32ca351ec4ffe1f02288475f780ad348 to your computer and use it in GitHub Desktop.
Fiken APIv2 - upload file with axios
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
import axios from "axios"; | |
import FormData from "form-data"; | |
import fs from "fs"; | |
const apiToken = "..." | |
const url = "..."; | |
const formData = new FormData(); | |
formData.append("file", fs.createReadStream(__dirname + '/test.pdf')); | |
formData.append("filename", "test.pdf"); | |
formData.append("comment", "Kommentar"); | |
axios.post(url, formData, { | |
headers: { | |
'Authorization': 'Bearer ' + apiToken, | |
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}` | |
} | |
}).then(res => console.log(res.status); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment