aboutsummaryrefslogtreecommitdiffstats
path: root/app/middlewares/multer.ts
blob: f35ca08aad8808599ad4a132fe4527a49982d129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import multer from 'multer';

const storage = multer.diskStorage({
    destination: '/tmp/www-uploads',
    filename: function (req, file, cb) {
        const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
        cb(null, file.fieldname + '-' + uniqueSuffix)
      }
});
export const upload = multer({ 
    storage: storage,
    limits: {
        fileSize: 1024 * 1024 * 500 
    },
    fileFilter: function (req, file, cb) {
        if (!file.originalname.match(/\.(zip)$/)) {
            return cb(new Error('Only accepting zip files'));
        }
        cb(null, true);
    }
});