使用 busboy 解析 multipart/form-data,添加 preservePath 选项以保留文件路径
This commit is contained in:
@@ -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 });
|
||||
const busboy = Busboy({ headers: req.headers, preservePath: true });
|
||||
const fields: any = {};
|
||||
let file: any = null;
|
||||
let filePromise: Promise<void> | null = null;
|
||||
@@ -33,7 +33,7 @@ router.post('/api/micro-app/upload', async (req, res) => {
|
||||
|
||||
busboy.on('file', (fieldname, fileStream, info) => {
|
||||
const { filename, encoding, mimeType } = info;
|
||||
const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}-${filename}`);
|
||||
const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`);
|
||||
const writeStream = createWriteStream(tempPath);
|
||||
const hash = crypto.createHash('md5');
|
||||
let size = 0;
|
||||
|
||||
Reference in New Issue
Block a user