Created
June 12, 2023 05:15
-
-
Save wwwins/8c0f7499e8df02e6a2dc5bae0288e6db to your computer and use it in GitHub Desktop.
Uploading an image(binary data) with 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
/** | |
* | |
* Uploading binary data with nodejs | |
* axios + fs.createReadStream | |
* | |
* */ | |
const fs = require('fs'); | |
const axios = require('axios').default; | |
const FormData = require('form-data'); | |
async function main(file) { | |
let data = new FormData() | |
const buffer = fs.createReadStream(file) | |
data.append('file', buffer) | |
const res = await axios.post('http://localhost/predict', data, { | |
headers: {'Content-Type': 'multipart/form-data',}, | |
}) | |
console.log(res.data) | |
} | |
main(...process.argv.slice(2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment