0
Follow
5
View

fs.readFileSync happening before multer uploaded files, ENOENT error

czzw818 注册会员
2023-01-25 13:00

Here is a simple snippet to get images as a base64. Without storing them into the disk.

const express = require('express');
const multer  = require('multer');
const storage = multer.memoryStorage();
const upload = multer({ storage });

const app = express();

app.post('/submit', upload.array('images'), (req, res, next) => {
  // req.files is array of `images` files
  // I believe it is a `Buffer` object.
  const base64Images = req.files.map(image => buffer.toString('base64'));
  // Ready to save into DB;
  console.log(base64Images);
})

About the Author

Question Info

Publish Time
2023-01-25 13:00
Update Time
2023-01-25 13:00