Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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? #1236

Open
hungattack opened this issue Oct 8, 2023 · 1 comment

Comments

@hungattack
Copy link

hungattack commented Oct 8, 2023

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);
@joeyguerra
Copy link

Does bun have a crypto.randomBytes module and API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants