multer
multer copied to clipboard
Upload file use Multer with Multer-gridfs-storage in environment of bun is not working but when I use environment of nodejs then it's working?
const storage = new GridFsStorage({
url: URL,
cache: true,
file: (req: any, files: any) => {
return new Promise((resolve, reject) => {
// is not running in here
try {
crypto.randomBytes(16, (err: any, buf: { toString: (arg0: string) => any }) => {
if (err) {
return reject(err);
}
const id = primaryKey();
const filename = buf.toString('hex') + path.extname(files.originalname);
const fileInfo = {
filename: filename,
bucketName: 'uploads',
metadata: {
id_file: id, // Trường để lưu _id của tệp tin
},
};
resolve(fileInfo);
});
} catch (error) {
console.log(error);
}
});
},
});
console.log(storage, 'storage');
export const upload = multer({ storage: storage });
router.post('/sendChat', upload.array('files'), sendChatController.sendChat);
Does bun
have a crypto.randomBytes
module and API?