-
-
Save cp2004/0495496da63047fb57b7fc33bd5138b5 to your computer and use it in GitHub Desktop.
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 { readFileSync } from 'fs'; | |
const FormData = require('form-data'); | |
const file = readFileSync('./whistle_v2.gcode', 'utf-8'); | |
let form = new FormData(); | |
form.append("file", file, { | |
filepath: "whistle_v2.gcode" | |
}); | |
form.getLength((err, length) => { // This function is redundant | |
const instance = axios.create({ | |
baseURL: 'http://localhost/api/', | |
headers: { | |
'X-Api-Key': '<api-key>', | |
}, | |
timeout: 10000 | |
}); | |
instance.post('/files/local', form, { | |
headers: { | |
...form.getHeaders(), | |
'Content-Length': form.getLengthSync(), | |
}, | |
}).then(res => { | |
console.log(res.data); | |
}).catch(err => { | |
console.log(err); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment