Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
request in node works but in js (vue) doesnt

Hi I have a backend which receive a request with a picture and storage, I try it with postman and with the code below and works perfectly

var axios = require('axios')
var FormData = require('form-data')
var fs = require('fs')
var data = new FormData()
data.append('file', fs.createReadStream('index.png'))
console.log('HEADERS')
console.log(data.getHeaders())
let config = {
  method: 'post',
  url: 'http://localhost:5013/v1/business/honda/widget/test/',
  headers: {
    ...data.getHeaders(),
  },
  data: data,
}

The problem is in my vue app I try to do it with the next code, I have 2 buttons with one load the image and the other to send it. In the back end I have the follow error when try to pick 'file'

http: no such file

 let imageData
//send the image to backend
    function funtest() {
      console.log('image')

      const formData = new FormData()
      const url = 'http://localhost:5013/v1/business/honda/widget/test/'

      formData.append('file', imageData)
      let config = {
        method: 'post',
        url: url,
        headers: {
          'Content-type': 'multipart/form-data',
        },
        data: formData,
      }
      axios(config)
        .then((response) => {
          console.log('RESPONSE')
          console.log(response)
        })
        .catch((error) => {
          console.log('ERROR')
          console.log(error)
        })
    }

//function to read the image 
    function onImage(data) {
      const reader = new FileReader()
      reader.onload = (e) => {
        imageData = e.target.result
        console.log('imagen')
      }
      reader.readAsDataURL(data.target.files[0])
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think it's probably not reading the path to index.png file correctly here, fs.createReadStream('index.png')

Consider using path like this

const path = require('path');

const filePath = path.join(__dirname,  'index.png');

data.append('file', fs.createReadStream(filePath))

NB: This is just a quick and dirty suggestion, and it's not guaranteed to work but it's definitely worth a shot

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda