J
J
John2015-05-10 23:39:24
Node.js
John, 2015-05-10 23:39:24

How to correctly organize file upload through a form in NodeJs?

There are many places where such a file upload to the server is described.

var fs   = require('fs');

router.post( '/api/upload/avatar', function( req, res ) {
    var File = fs.createWriteStream( "newimage.jpg");
    req.pipe( File );
})

The file is loaded, but the file is broken.
Tell me how to properly organize the download of the file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-05-11
@MarcusAurelius

For the sake of Allah, take the multiparty library, there can also be many files in one form and many files even in one file field. There is a complex format, MIME, you can't just write everything to the stream. All this needs to be parsed https://www.npmjs.com/package/multiparty examples are there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question