Mark
Mark

Reputation: 33571

node.js knox tutorial - how to upload files with node.js

How do I use knox to upload a file with node.js?

https://github.com/LearnBoost/knox

What's the full code for uploading to node.js, from the route to the uploading with knox? I think the documentation there only covers the part where they put it onto s3.

The put example:

fs.readFile('Readme.md', function(err, buf){
  var req = client.put('/test/Readme.md', {
      'Content-Length': buf.length
    , 'Content-Type': 'text/plain'
  });
  req.on('response', function(res){
    if (200 == res.statusCode) {
      console.log('saved to %s', req.url);
    }
  });
  req.end(buf);
});

But where does Readme.md come from?

Thanks.

Upvotes: 1

Views: 2704

Answers (3)

rafidude
rafidude

Reputation: 4626

You may use connect-form to upload a file. It uses node-formidable library behind the scenes. Here is an example that shows how to use express.js and connect-form to upload files from a page/form.

Upvotes: 0

Mark
Mark

Reputation: 33571

OK, node-formidable. Got it. That's the correct plugin.

Upvotes: 3

generalhenry
generalhenry

Reputation: 17319

Readme.md is part of the knox package, it's in the root of the knox folder, so running from that folder there's no need for using __dirname. It's simply a relative file path to a file in the same folder.

Upvotes: -1

Related Questions