Upload file using NodeJS and node-formidable

后端 未结 2 665
太阳男子
太阳男子 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; });
    
    0 讨论(0)
  • 2021-02-02 01:58

    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

    0 讨论(0)
提交回复
热议问题