0

I have an express based server side script to upload images and it works fine if I use a html form for uploading. Now, I don't want to use this form and I want to upload files that are stored in filesystem via fs library. I want to do it with another different nodejs script.

Is this possible?

1 Answers1

1

I'll suggest to check request module or specifically this part of the documentation https://github.com/mikeal/request#forms

Here is an example:

var r = request.post('http://service.com/upload', function optionalCallback (err, httpResponse, body) {
  if (err) {
    return console.error('upload failed:', err);
  }
  console.log('Upload successful!  Server responded with:', body);
})
var form = r.form()
form.append('my_field', 'my_value')
form.append('my_buffer', new Buffer([1, 2, 3]))
form.append('my_file', fs.createReadStream(path.join(__dirname, 'doodle.png')))
form.append('remote_file', request('http://google.com/doodle.png'))
Krasimir
  • 13,306
  • 3
  • 40
  • 55