multer icon indicating copy to clipboard operation
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?

Open hungattack opened this issue 8 months ago • 1 comments

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);

hungattack avatar Oct 08 '23 12:10 hungattack

Does bun have a crypto.randomBytes module and API?

joeyguerra avatar Apr 01 '24 22:04 joeyguerra