Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!