Estou tentando enviar imagens via método POST no axios, porém quando executo o script, ele me da esse erro:
error:
{ code: 500,
error_id: 'server_error',
description: 'Error parsing request into form data' } } }
Meu script
var app = require('express')();
var fs = require('fs');
var axios = require('axios');
var param = {
images_file: fs.createReadStream( __dirname + '/robot_orthographic.jpg')
}
axios({
method: 'POST',
url: 'https://gateway.watsonplatform.net/visual-recognition/api/v3/classify?version=2018-03-19',
param,
config: {
headers: {'Content-Type': 'multipart/form-data' }
},
auth: {
username: 'apiKey',
password: 'KEY'
}
}).then(function(response){
console.log(response.data);
}).catch(function(err){
console.log(err);
});
app.listen(3000, function(){
console.log('servidor rodando!');
});
Já tentei usar a lib form-data
porém continua com o mesmo erro.
images_file: fs.readFile( __dirname + '/robot_orthographic.jpg', 'utf8')
?const files = new FormData() files.append('files', this.banners.files) files.append('json', JSON.stringify(data))