strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
4.01k stars 533 forks source link

Getting the file name and type when uploading #1850

Open offbrok opened 2 years ago

offbrok commented 2 years ago

Framework: sanic Is there any way to get the name and type of the uploaded file? We are currently using this implementation:

for _, file_list in info.context.req.files.items():
    file_name = file_list[0].name
    file_size = len(file_list[0].body)
    file_type = file_list[0].type

Is there a more correct way to get this data using the Upload scalar?

Upvote & Fund

Fund with Polar

patrick91 commented 2 years ago

@offbrok yes, unfortunately the current implementation of Upload returns a BytesIO object for Sanic:

image

we might want to change that