Express 4: How to upload file to memory (e.g. as a UTF-8 string) rather than disk? Express 4: How to upload file to memory (e.g. as a UTF-8 string) rather than disk? express express

Express 4: How to upload file to memory (e.g. as a UTF-8 string) rather than disk?


I don't know if this option was available at the time of the question, but it certainly is now.You can set the inMemory option to true in multer and that will give you a buffer object. Likes this:

app.use(multer({    dest: './uploads/',    inMemory: true}));

You can find all the available options for multer here: https://github.com/expressjs/multer#options


Update for multer 1.x

Multer version 1.0.0 introduces the concept of storage engines and ships with two default engines: DiskStorage and MemoryStorage.

This is how you can instantiate it to store the files in memory:

multer({ storage: multer.memoryStorage({}) })