fix uploads encoding (cyrilic)
This commit is contained in:
@ -9,12 +9,17 @@ import { createRouter } from 'next-connect';
|
||||
// Generalized Multer configuration
|
||||
const storage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
const uploadPath = path.join(process.cwd(), 'public/content', req.query.subfolder as string);
|
||||
fs.mkdir(uploadPath, { recursive: true }).then(() => cb(null, uploadPath)).catch(cb);
|
||||
const subfolder = req.query.subfolder ? decodeURIComponent(req.query.subfolder as string) : 'default';
|
||||
const uploadPath = path.join(process.cwd(), 'public/content', subfolder);
|
||||
|
||||
fs.mkdir(uploadPath, { recursive: true })
|
||||
.then(() => cb(null, uploadPath))
|
||||
.catch(cb);
|
||||
},
|
||||
filename: (req, file, cb) => {
|
||||
const prefix = req.body.prefix || path.parse(file.originalname).name;
|
||||
cb(null, `${prefix}${path.extname(file.originalname)}`);
|
||||
const filename = decodeURIComponent(file.originalname); // Ensure the filename is correctly decoded
|
||||
const prefix = req.body.prefix ? decodeURIComponent(req.body.prefix) : path.parse(filename).name;
|
||||
cb(null, `${prefix}${path.extname(filename)}`);
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user