🐞 fix: Handle Garbled Chinese Characters in File Upload (#2261)

Co-authored-by: 彭修照 <pengxiuzhao.uh@haier.com>
This commit is contained in:
pxz2016 2024-04-01 20:25:36 +08:00 committed by GitHub
parent 4854b39f41
commit cc92597f14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View file

@ -15,6 +15,7 @@ const storage = multer.diskStorage({
},
filename: function (req, file, cb) {
req.file_id = crypto.randomUUID();
file.originalname = decodeURIComponent(file.originalname);
cb(null, `${file.originalname}`);
},
});

View file

@ -125,7 +125,7 @@ const useFileHandling = (params?: UseFileHandling) => {
startUploadTimer(extendedFile.file_id, extendedFile.file?.name || 'File');
const formData = new FormData();
formData.append('file', extendedFile.file as File);
formData.append('file', extendedFile.file as File, encodeURIComponent(extendedFile.file?.name || 'File'));
formData.append('file_id', extendedFile.file_id);
if (extendedFile.width) {
formData.append('width', extendedFile.width?.toString());