Browse Source

better filenaming

master
Rich Brown 1 year ago
parent
commit
0855780d55
1 changed files with 4 additions and 1 deletions
  1. +4
    -1
      routes/createRouter.js

+ 4
- 1
routes/createRouter.js View File

@@ -2,13 +2,16 @@ import express from 'express';
import multer from 'multer';
// import Micropub from 'micropub-helper';
import fs from 'fs';
import path from 'path';

const storage = multer.diskStorage({
destination(req, file, cb) {
cb(null, 'uploads/');
},
filename(req, file, cb) {
cb(null, `${file.originalname}-${Date.now()}`);
const { originalname: { og } } = file;
const fiver = Math.random().toString(36).substr(2, 5);
cb(null, `${og}-${fiver}${path.extname(og)}`);
},
});
const upload = multer({ storage });


Loading…
Cancel
Save