This commit is contained in:
2026-01-22 23:29:20 +08:00
parent 3618d18915
commit bafd02452b
7 changed files with 33 additions and 10 deletions

View File

@@ -20,7 +20,7 @@ router.post('/api/micro-app/upload', async (req, res) => {
if (!tokenUser) return;
// 使用 busboy 解析 multipart/form-data
const busboy = Busboy({ headers: req.headers, preservePath: true });
const busboy = Busboy({ headers: req.headers, preservePath: true, defCharset: 'utf-8' });
const fields: any = {};
let file: any = null;
let filePromise: Promise<void> | null = null;
@@ -33,6 +33,8 @@ router.post('/api/micro-app/upload', async (req, res) => {
busboy.on('file', (fieldname, fileStream, info) => {
const { filename, encoding, mimeType } = info;
// 处理 UTF-8 文件名编码
const decodedFilename = typeof filename === 'string' ? Buffer.from(filename, 'latin1').toString('utf8') : filename;
const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`);
const writeStream = createWriteStream(tempPath);
const hash = crypto.createHash('md5');
@@ -59,7 +61,7 @@ router.post('/api/micro-app/upload', async (req, res) => {
writeStream.on('finish', () => {
file = {
filepath: tempPath,
originalFilename: filename,
originalFilename: decodedFilename,
mimetype: mimeType,
hash: hash.digest('hex'),
size: size,