Upload file using NodeJS and node-formidable

狂风中的少年 提交于 2019-12-02 19:36:16

The problem is the that files.upload is not the content of the file, it is an instance of the File class from node-formidable.

Look at:

https://github.com/felixge/node-formidable/blob/master/lib/file.js

Instead of trying to write the file to disk again, you can just access the path to uploaded file like this and use fs.rename() to move it where you want:

fs.rename(files.upload.path, 'yournewfilename', function (err) { throw err; });

Is the form set to enctype="multipart/form-data"?

I've only used formidable with Express - the Express example works fine:

https://github.com/visionmedia/express/tree/master/examples/multipart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!