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?

2
  • you can use socket connections Commented Jul 3, 2014 at 8:01
  • You can use http.request, but you'll apparently need to format the POST contents yourself. See stackoverflow.com/questions/5744990/… Commented Jul 3, 2014 at 8:06

1 Answer 1

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'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.