Skip to content

Commit

Permalink
Better file handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZandercraftGames committed Sep 27, 2023
1 parent 56ffe3e commit 4a10113
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ const logger = require('morgan')
const multer = require('multer')

// Setup multer disk-store
const upload = multer({ dest: 'uploads/' })
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'uploads/')
},
filename: (req, file, cb) => {
const uniquePrefix = Date.now() + '-' + Math.round(Math.random() * 1E9)
cb(null, uniquePrefix + '-' + file.originalname)
}
})
const upload = multer({ storage: storage })

// --- Routers ---
const indexRouter = require('./routes/index')
Expand Down

0 comments on commit 4a10113

Please sign in to comment.