Skip to content

Instantly share code, notes, and snippets.

@mzalazar
Created November 21, 2018 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzalazar/3d40e3da8059c13ad42f0ef0f4dd8aa0 to your computer and use it in GitHub Desktop.
Save mzalazar/3d40e3da8059c13ad42f0ef0f4dd8aa0 to your computer and use it in GitHub Desktop.
Upload a file from node.js
const FormData = require('form-data')
const request = require('request')
let form = new FormData()
let filename = `/myData/data.gz`
form.append('file', fs.createReadStream(filename))
let options = {
url: `http://myServer/uploadFile`,
method: 'POST',
formData: {
file: fs.createReadStream(filename),
additionalFieldPosted: 'hello' // you can get rid of this
}
}
request(options, (err, response, body) => {
if (err) return done(err)
// body will be the server response =)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment