You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

23 lines
543 B

  1. import multer from 'multer';
  2. import crypto from 'crypto';
  3. import os from 'os';
  4. const tmpFolder = os.tmpdir();
  5. export default {
  6. tempdir: {
  7. directory: tmpFolder,
  8. storage: multer.diskStorage({
  9. destination: tmpFolder,
  10. filename(request, file, callback) {
  11. const fileHash = crypto.randomBytes(10).toString('hex');
  12. const originalname = file.originalname.replace(/[^0-9-a-zA-Z.]/g, '-');
  13. const filename = `${fileHash}-${originalname}`;
  14. return callback(null, filename);
  15. },
  16. }),
  17. },
  18. };