Open nkma-ml opened 2 weeks ago
Hey, I had a similar type error which I fixed by using the word 'data' as the function parameter name. I'm a complete noob so this might be a long shot but it's worth trying.
Replace
async def upload_files(file_upload: Upload):
With
async def upload_files(data: Upload):
Hey, I had a similar type error which I fixed by using the word 'data' as the function parameter name. I'm a complete noob so this might be a long shot but it's worth trying.
Replace
async def upload_files(file_upload: Upload):
With
async def upload_files(data: Upload):
That is not it, unfortuanetly. It's also just a parameter name, so would really suprise me.
I see what the problem is. When using a validation decorator like @validate_request or @validate_querystring, quart-schema returns specific arguments to your route function, (data for validate_request and query_args for validate_querysting). All you have to do it annotate your route function with the appropriate arg and type and you're good to go.
from pydantic import BaseModel
from quart_schema import DataSource, validate_request
from quart_schema.pydantic import File
class Upload(BaseModel):
file: File
@file_content_bp.route("/upload_file", methods=["POST"])
@validate_request(Upload, source=DataSource.FORM_MULTIPART)
async def upload_files(data: Upload):
file = data.file
file_content = file.stream.read()
logging.info(file_content)
# save the file
file.save(file.name)
return {"status":"success"}
Your code can then be rewritten as above.
Hello.
I'm trying to add schema validation to an upload file endpoint. It looks as follows:
When I try to invoke it using the following request:
I get the following error:
Seems like it could be a bug, or am I missing something. The package versions are: quart==0.19.6 quart-schema[pydantic]==0.20.0
Hopefully it's not me having a brainfart.
BR, Niels