用python检索表单数据

用python检索表单数据,python,curl,fastapi,Python,Curl,Fastapi,我不熟悉网络交流。 我使用ubuntu并尝试学习fastapi。 假设我使用curl发布了一个文件。似乎大家都认为这是最好的方法: curl-F“file=@image1.jpg”-v 现在,在服务器端,我想检索图像,并为每个像素值添加1,然后返回它。但是我现在已经知道如何从curl中“捕捉”图像了,我该怎么做?现在,我只有下面的虚拟函数,它不做任何智能操作: @app.post("/image") async def post_test(): print("

我不熟悉网络交流。 我使用ubuntu并尝试学习fastapi。 假设我使用curl发布了一个文件。似乎大家都认为这是最好的方法:

curl-F“file=@image1.jpg”-v

现在,在服务器端,我想检索图像,并为每个像素值添加1,然后返回它。但是我现在已经知道如何从curl中“捕捉”图像了,我该怎么做?现在,我只有下面的虚拟函数,它不做任何智能操作:

@app.post("/image")
async def post_test():
    print("I don't know how to catch the image :( ")
    return {"You sent an image..."}

请帮助我如何编写post_测试函数!(烧瓶也可以。)

您可以查看我的SO答案中的完整答案,以了解类似的问题()

基本上,您必须将代码更改为

from fastapi import FastAPI, UploadFile, File


app = FastAPI()


@app.post("/file/")
async def create_upload_file(file: UploadFile = File(...)):
    # Access your file object via file.file,
    # and perform all the necessary transformations
    # Return the filename, but you may return the file itself
    return {"filename": file.filename}

你看过文档了吗?非常感谢。正是我想要的。