Upload file using NodeJS and node-formidable

后端 未结 2 668
太阳男子
太阳男子 2021-02-02 01:06

I succeed uploading file using node.js and the formidable module yet, the file that got save on the disk is in some kind of a bad format ( bad encoding) e.g. if I upload an imag

2条回答
  •  醉话见心
    2021-02-02 01:51

    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; });
    

提交回复
热议问题