P
P
Popkornikus2020-12-04 21:16:36
Node.js
Popkornikus, 2020-12-04 21:16:36

Why are files uploaded to a folder without an extension?

Good afternoon. I use multer to upload files to folders, but the extension is not added to the file when uploading. Why is that?

const {Router}= require('express')
const router = Router()
const multer  = require("multer");

const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        if (file.mimetype === 'text/plain') {
            cb(null, 'public/')
        } else if (file.mimetype === 'image/jpeg') {
            cb(null, 'public/FilmImage')
        } else {
            console.log(file.mimetype)
            cb({error: 'Mime type not supported'})
        }
    },
    filename: function (req, file, cb) {
        cb(null, file.fieldname + '-' + Date.now())
    }
});


const upload = multer({storage: storage});

router.post ('/addContent',upload.any(), (req, res) => {
    console.log(req.files);
})

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question