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

dynamic upload path or callback when upload done #1

Open
chinhtrandn opened this issue Dec 11, 2021 · 1 comment
Open

dynamic upload path or callback when upload done #1

chinhtrandn opened this issue Dec 11, 2021 · 1 comment

Comments

@chinhtrandn
Copy link

How to edit dynamic upload path or callback when upload done?
Thank

@chanphiromsok
Copy link
Owner

First of all I apologies I did not know you open the issue here I think it can
you can implement like so

const multer = require('multer')
const storage = multer.diskStorage({
destination: (req, file, cb) => {
  const { userId } = req.body
  const dir = ./uploads/${userId}
  fs.exists(dir, exist => {
  if (!exist) {
    return fs.mkdir(dir, error => cb(error, dir))
  }
  return cb(null, dir)
  })
},
filename: (req, file, cb) => {
  const { userId } = req.body
  cb(null, UserId-${userId}-Image-${Date.now()}.png)
}
})
const upload = multer({ storage })

expressjs/multer#556 please check this issue for more info

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