api_file.py 511 字节
Newer Older
Libcat's avatar
Libcat 已提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from typing import List, Optional

from fastapi import APIRouter, UploadFile, File
from pathlib import Path

import apischemas as api
import database as db

router = APIRouter(tags=["文件操作"], prefix="/upload")


@router.post("/")
async def create_upload_file(file: UploadFile = File(...)):
    content = await file.read()
    with open(Path("upload")/Path(file.filename), 'wb') as f:
        f.write(content)
    return {"filename": file.filename, "content_type": file.content_type, "size": len(content)}