Multer: Convert multer file to string

Created on 12 Dec 2015  路  3Comments  路  Source: expressjs/multer

Hi,

I'm using multer to read in a file using multi-part form data. However, I don't want to upload the file, but I want to read the file contents into a string. Is there a way to do this?

Most helpful comment

var storage = multer.memoryStorage();
    var upload = multer({ 
    storage: storage
});
router.post('/', upload.single('uploadExcel'), function (req, res) {

    var uploadExcel = req.file;    
    var buffer = uploadExcel.buffer;

    return res.status(200).send("Nice!");
});

All 3 comments

var storage = multer.memoryStorage();
    var upload = multer({ 
    storage: storage
});
router.post('/', upload.single('uploadExcel'), function (req, res) {

    var uploadExcel = req.file;    
    var buffer = uploadExcel.buffer;

    return res.status(200).send("Nice!");
});

What @jdnichollsc said. Furthermore, if you really want it to be a string, and not a buffer, you can use the .toString() method on the buffer.

How can I send the file after I got it ? I would like to send from NodeJS to other process which reads multipart data

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tonghae picture tonghae  路  4Comments

kiwenlau picture kiwenlau  路  4Comments

tjabdoullah picture tjabdoullah  路  4Comments

trexanhvn picture trexanhvn  路  3Comments

atsepkov picture atsepkov  路  4Comments