Skip to content

Instantly share code, notes, and snippets.

@steingrd
Created March 19, 2020 17:44
Show Gist options
  • Save steingrd/32ca351ec4ffe1f02288475f780ad348 to your computer and use it in GitHub Desktop.
Save steingrd/32ca351ec4ffe1f02288475f780ad348 to your computer and use it in GitHub Desktop.
Fiken APIv2 - upload file with axios
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