const Framework = require("../../framework/node-core-framework.js"); const ossToolService = require('../services/oss_tool_service.js'); module.exports = { /** * @swagger * /api/file/upload_oss: * post: * summary: 上传文件到OSS * description: 将Base64编码的文件上传到阿里云OSS * tags: [前端-文件管理] * requestBody: * required: true * content: * application/json: * schema: * type: object * required: * - fileBase64 * properties: * fileBase64: * type: string * format: base64 * description: Base64编码的文件内容 * example: '/9j/4AAQSkZJRgABAQEAYABgAAD...' * responses: * 200: * description: 上传成功 * content: * application/json: * schema: * type: object * properties: * code: * type: integer * description: 状态码,0表示成功 * example: 0 * message: * type: string * description: 响应消息 * example: 'success' * data: * type: object * properties: * success: * type: boolean * description: 是否成功 * example: true * name: * type: string * description: OSS文件名称 * path: * type: string * description: OSS文件URL * ossPath: * type: string * description: OSS完整路径 * fileType: * type: string * description: 文件类型 * fileSize: * type: integer * description: 文件大小(字节) * originalName: * type: string * description: 原始文件名 * suffix: * type: string * description: 文件后缀 * storagePath: * type: string * description: 存储路径 * 400: * description: 参数错误 * content: * application/json: * schema: * type: object * properties: * code: * type: integer * example: 400 * message: * type: string * example: '缺少必要参数:fileBase64' * 500: * description: 服务器错误或上传失败 */ 'POST /file/upload_oss': async (ctx) => { const body = ctx.getBody(); const { fileBase64 } = body; // base 64 转buffer const buffer = Buffer.from(fileBase64, 'base64'); let result = await ossToolService.uploadStream(buffer, 'image/jpeg', 'jpg') return ctx.success(result); } }