update
This commit is contained in:
@@ -28,7 +28,7 @@ router.post('/api/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 = {};
|
||||
const files: any = [];
|
||||
const filePromises: Promise<void>[] = [];
|
||||
@@ -41,6 +41,8 @@ router.post('/api/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);
|
||||
|
||||
@@ -63,7 +65,7 @@ router.post('/api/app/upload', async (req, res) => {
|
||||
writeStream.on('finish', () => {
|
||||
files.push({
|
||||
filepath: tempPath,
|
||||
originalFilename: filename,
|
||||
originalFilename: decodedFilename,
|
||||
mimetype: mimeType,
|
||||
});
|
||||
resolve();
|
||||
|
||||
Reference in New Issue
Block a user