Tag: 身体分析器

如何使用multer或body-parser上传文件

我是一个NodeJS初学者,跟着一本书“使用MongoDB和NodeJS进行Web开发”。 我在“第6章”中被卡住了。 当我使用Muller进行file upload时,服务器会引发以下错误: /Users/fk / Documents / imageuploader / node_modules / express / lib / application.js: 209 throw new TypeError('app.use() requires middleware functions'); ^ TypeError: app.use() requires middleware functions 但是当我用bodyParserreplace它时,服务器启动,但是当我点击上传button时,它给我在浏览器上的以下错误。 500 TypeError: Cannot read property 'file' of undefined 但是,它应该将我redirect到另一个页面,其中显示上传的文件。 这里是我的bodyParser代码,请看我是否正确使用它,因为它在服务器启动时给我“body-parser deprecated”。 我看过其他的问题,像我和我一样,但没有一个真正的工作。 app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser({ uploadDir: path.join(__dirname, '../public/upload/temp') })); 下面的代码显示了我如何使用Muller,以防万一如果有什么我不该做的,请让我知道。 在上传文件,body-parser或multer的情况下哪个更好? […]