在本教程中,我实现了文件上传的一个变体:
https://strawberry.rocks/docs/guides/file-upload个
代码基本上是这样的:
import typing
import strawberry
from strawberry.file_uploads import Upload
@strawberry.input
class FolderInput:
files: typing.List[Upload]
@strawberry.type
class Mutation:
@strawberry.mutation
async def read_file(self, file: Upload) -> str:
[do some processing]
return "Processing of PDF done!"
我使用下面的调用对其进行测试:
curl localhost:8000/graphql \
-F operations='{ "query": "mutation($file: Upload!){ readFile(file: $file) }", "variables": { "file": null } }' \
-F map='{ "file": ["variables.file"] }' \
-F file=@/path/to/some_file.pdf
CURL
调用调用readFile
,而Strawberry
中的Mutations 使用read_file
,映射在哪里完成,我们能控制吗?我想要多个读取方法(例如read_typeA_pdf
、read_typeB_pdf
等).