Files
RuoYi-Vue3-FastAPI/ruoyi-fastapi-backend/module_admin/service/common_service.py
2024-01-22 23:46:27 +08:00

19 lines
508 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from fastapi import UploadFile
class CommonService:
"""
通用模块服务层
"""
@classmethod
def upload_service(cls, path: str, task_path: str, upload_id: str, file: UploadFile):
filepath = os.path.join(path, task_path, upload_id, f'{file.filename}')
with open(filepath, 'wb') as f:
# 流式写出大型文件这里的10代表10MB
for chunk in iter(lambda: file.file.read(1024 * 1024 * 10), b''):
f.write(chunk)