开发者

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

开发者 https://www.devze.com 2023-02-11 01:58 出处:网络
How do I开发者_如何学JAVA use knox to upload a file with node.js? https://github.com/LearnBoost/knox

How do I开发者_如何学JAVA 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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消