尝试上传时什么也没发生

发布于 2024-11-03 22:15:17 字数 1399 浏览 0 评论 0原文

我想通过node.js上传文件,所以我尝试通过这篇文章。 http://debuggable.com/posts/parsing-file-uploads-at-500-mb-s-with-node-js:4c03862e-351c-4faa-bb67-4365cbdd56cb

我 当我上传文件时运行此代码

var formidable = require('formidable')
  , http = require('http')
  , sys = require('sys');

var server=http.createServer(function(req, res) {
    console.log('out if condition'+sys.inspect(req));
  if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
    // parse a file upload
    console.log('in if condition');
    var form = new formidable.IncomingForm();
    form.parse(req, function(fields, files) {
      res.writeHead(200, {'content-type': 'text/plain'});
      res.write('received upload:\n\n');
      res.end(sys.inspect({fields: fields, files: files}));
    });
    return;
  }

  // show a file upload form
  res.writeHead(200, {'content-type': 'text/html'});
  res.end
    ( '<form action="/upload" enctype="multipart/form-data" method="post">'
    + '<input type="text" name="title"><br>'
    + '<input type="file" name="upload" multiple="multiple"><br>'
    + '<input type="submit" value="Upload">'
    + '</form>'
    );
});
server.listen(8000);

,它不会轻松地进一步进行,并且不会进入上传条件,为什么?

i want to upload a file by node.js so i try by this article.
http://debuggable.com/posts/parsing-file-uploads-at-500-mb-s-with-node-js:4c03862e-351c-4faa-bb67-4365cbdd56cb

I run this code

var formidable = require('formidable')
  , http = require('http')
  , sys = require('sys');

var server=http.createServer(function(req, res) {
    console.log('out if condition'+sys.inspect(req));
  if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
    // parse a file upload
    console.log('in if condition');
    var form = new formidable.IncomingForm();
    form.parse(req, function(fields, files) {
      res.writeHead(200, {'content-type': 'text/plain'});
      res.write('received upload:\n\n');
      res.end(sys.inspect({fields: fields, files: files}));
    });
    return;
  }

  // show a file upload form
  res.writeHead(200, {'content-type': 'text/html'});
  res.end
    ( '<form action="/upload" enctype="multipart/form-data" method="post">'
    + '<input type="text" name="title"><br>'
    + '<input type="file" name="upload" multiple="multiple"><br>'
    + '<input type="submit" value="Upload">'
    + '</form>'
    );
});
server.listen(8000);

when i upload the file it doesn't proceed further easily and doesn't go in if condition of upload why ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断桥再见 2024-11-10 22:15:17
 fs.writeFile(files.upload.name, files.upload,'utf8', function (err) {
                      if (err) throw err;
                      console.log('It\'s saved!');
                });

请检查。

http://rahulmehta1. wordpress.com/2011/04/26/uploading-a-file-in-node-js-by-formidable/

 fs.writeFile(files.upload.name, files.upload,'utf8', function (err) {
                      if (err) throw err;
                      console.log('It\'s saved!');
                });

Please check.

http://rahulmehta1.wordpress.com/2011/04/26/uploading-a-file-in-node-js-by-formidable/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文