Parse error while uploading images from Xios

Asked

Viewed 190 times

0

I’m trying to send images via POST method in Xios, but when I run the script, it gives me this error:

  error:
       { code: 500,
         error_id: 'server_error',
         description: 'Error parsing request into form data' } } }

My 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!');
});

I’ve tried using the lib form-data but still with the same mistake.

  • Sending a json + a file?

  • @Frame an image to be more specific

  • Have you tried sending the file with images_file: fs.readFile( __dirname + '/robot_orthographic.jpg', 'utf8')?

  • @Sergio so now the error has changed from 400 to 500

  • I had to do something similar to . net core using form data and adapting the model: const files = new FormData()
 files.append('files', this.banners.files)
 files.append('json', JSON.stringify(data))

  • Until that question: https://answall.com/questions/387331/como-enviar-uma-requisi%C3%A7%C3%A3o-post-com-files-e-json/387380#387380

  • @Also Rconi did not work, he is complaining of parse: Error parsing request into form data

  • I don’t know how to do it with express. A tip if you can’t get out of the problem: Create an API to send the file and another to send the json.

  • @Marconi is also not believe that it is the express, but rather the Axios that should not be passing some parameter because the api returns Error parsing request into form data

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.