Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sync-request 'ERROR': Error: source.on is not a function

By using the following code, I’m trying to upload a local file to an url but I keep having "Error: source.on is not a function"
Probably is related to the second parameter of the fd.append, but honestly I don’t know what to put there as there are many different approaches and solutions but none worked so far.

Any clues?

let file='screenshot.png'
let url='...some url...'

const fd = new FormData()
fd.append('screenshotFile', fs.createReadStream(file), 'screenshot.png')

try {
  request('POST', url', {form: fd})
}
catch(e){
  logger.log('ERROR',e)
}

Result :
‘ERROR’: Error: source.on is not a function

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

createReadStream returns a ReadStream, but form data doesn’t accept it.

Use readFileSync instead 🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading