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

Questions : multer filename & metadata options #51

Open
PierreBrisorgueil opened this issue Apr 29, 2020 · 2 comments
Open

Questions : multer filename & metadata options #51

PierreBrisorgueil opened this issue Apr 29, 2020 · 2 comments
Assignees

Comments

@PierreBrisorgueil
Copy link

PierreBrisorgueil commented Apr 29, 2020

Hello,

first of all thank you for this work which simplifies a lot of things. I just have a little quesiton after playing with a lot of tests.

Do we have other options than playing with this kind of tricks to redefine metada & filename with multer?

https://github.com/ekline-expnet/mongoose-gridfs-multer/blob/master/index.js

thanks for your time

@lykmapipo
Copy link
Owner

@PierreBrisorgueil

If you look on mongoose-gridfs multer implementation, file metadata and aliases are derived from the incoming http request.

Options: redefine metada & filename with multer?

  1. Include metadata and aliases from the request source. No code changes
  2. mongoose-gridfs to allow options for getFilename and getMetadata - Require code changes

@lykmapipo lykmapipo self-assigned this Apr 29, 2020
@PierreBrisorgueil
Copy link
Author

@lykmapipo Ok :) thx for this informations !

  1. Hum, i will try to add a middleware before multer.upload to play on this, already tryed that but maybe too quickly
  2. yep, a feature like that could be interesting to further simplify the handling

to give ideas with alternative example :

const GridFsStorage = require('multer-gridfs-storage');
new GridFsStorage({
      db: connection,
      file: (req, file) => new Promise((resolve, reject) => {
        crypto.randomBytes(32, (err, buf) => {
          if (err) return reject(err);
          const fileInfo = {
            metadata: { user: req.user._id },
            filename: buf.toString('hex') + path.extname(file.originalname),
            bucketName: 'uploads',
          };
          resolve(fileInfo);
        });
      }),

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

No branches or pull requests

2 participants