【问题标题】:Nodejs query for uploading photos上传照片的Nodejs查询
【发布时间】:2014-06-24 03:27:35
【问题描述】:

我是nodejs 的新手。我基本上使用express,我必须创建一个表单来上传照片。到目前为止,我已经创建了一个名为 upload.handlebars 的文件,我在其中编写了以下代码:

<form enctype="multipart/form-data" action="uploads" method="post"> 
<input type="file", id = "image", name="image", accept="image/*"> 
<input type='submit' id='tags' value='Upload'>

我有另一个名为 router.js 的文件,我在其中编写了 post 函数。 post函数中的一行是:

fs.readFile(req.files.image.path, function (err, data) {

但是,我收到如下错误:

TypeError: Cannot read property 'image' of undefined at Object.handle....

我应该如何在我的router.js 中指定图像文件的“名称”?

【问题讨论】:

  • 中的逗号是什么?

标签: node.js


【解决方案1】:

确保您已启用多方中间件。

https://github.com/andrewrk/connect-multiparty

不附带最新快递。

【讨论】:

    【解决方案2】:

    您可以使用 express 快速解决此问题。了解更多请阅读以下页面express api reference

    现在下面的代码可能会对你有所帮助 -

    app.post('<your path>',express.bodyParser(),function(req,res){
        console.log(req.files);//to get all the files uplaoded
    });
    

    确保 express 版本应该是 3.4

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 2020-01-13
      • 2018-10-14
      • 2013-08-23
      • 2011-06-04
      • 2017-02-18
      相关资源
      最近更新 更多