Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda