Files

24 lines
592 B
Python
Raw Permalink Normal View History

2026-09-19 10:41:18 +08:00
from typing import Annotated
from fastapi import Depends, FastAPI,APIRouter,Form,File,UploadFile
from fastapi.security import OAuth2PasswordRequestForm
route = APIRouter(prefix="/file",tags=["file"])
@route.post("/bytes")
def bytes(file:bytes = File()):
print("bytes:\t" + str(file))
print("str:\t" + file.decode("utf-8"))
return file.decode("utf-8")
@route.post("/uploadfile")
async def uploadfile(file:UploadFile):
data = await file.read()
print("bytes:\t" + str(data))
print("str:\t" + data.decode("utf-8"))
return data.decode("utf-8")
# text read/write