添加delete, query的api, 修复上传中文名文件乱码的问题

This commit is contained in:
539943419 committed 2024-08-11 22:39:20 +08:00
1 parent 737ee87bae
commit 64259e37f4
10 files changed
+323 -14

No files matched your search

+8 -3
View File
@@ -1,15 +1,20 @@
import path from "path";
import fs from "fs";
import multer from "multer";
import { api_upload, staticPath } from "../config.js";
import { api, staticPath } from "../config.js";
const api_upload = api.upload
const storage = multer.memoryStorage();
const upload = multer({ storage: storage }).single('file');
export default function useUploadApi(app) {
app.post(api_upload, upload, (req, res) => {
const decodedPath = decodeURIComponent(req.path).substring(8);
const savePath = path.join(staticPath, decodedPath, req.file.originalname)
// 必须这样传,不然中文乱码
const fileName = req.body.fileName
const decodedPath = decodeURIComponent(req.path).substring(api_upload.length - 1);
const savePath = path.join(staticPath, decodedPath, fileName)
// 覆盖写or追加写
const oprateType = req.body.oprateType === 'write' ? 'write' : 'append'
const data = req.file.buffer