Created
November 21, 2018 14:56
-
-
Save mzalazar/3d40e3da8059c13ad42f0ef0f4dd8aa0 to your computer and use it in GitHub Desktop.
Upload a file from node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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