Open slamer59 opened 3 years ago
The last proposal with router seems to not override the POST method. Any idea ? I don't see an exemple.
It's working ! With:
from fastapi.datastructures import UploadFile
from LAPD import Document
from pydantic import BaseModel
from fastapi import FastAPI, UploadFile
from fastapi import File as FastFile
from fastapi_crudrouter import MemoryCRUDRouter as CRUDRouter
from LAPD.core import File
import shutil
app = FastAPI()
router = CRUDRouter(
schema=File,
)
@router.post("/")
async def upload_file(file: UploadFile = FastFile(...)):
with open(f"{file.filename}", "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
return File(absolute_path=f"{file.filename}")
app.include_router(router)
but why is it working with the path @router.post('')
and not @router.post('/file')
?
In fact, it is not keep it into memory... Even adding id: int to the attributes.
Hi @slamer59, sorry for the delayed response. did you manage to get it working?
Dont be :) No avance on my side.
Hello, First of all, I am not an expert of FastAPI... so it might not be related at all to fastapi-crudrouter.
I have Pydantic class which holds file metadata:
I read the documentation to do something like this but I don't know what to put in CreateFile class ?
In pure FastAPI, upload is done here:
Any ideas if it is possible and how ?
Maybe with this routing functionality ? https://fastapi-crudrouter.awtkns.com/routing
Regards