我有以下型別的 FastAPI:
@app.post("/extract_text")
async def create_upload_file(upload_file: UploadFile = File(...)):
return FileResponse(path="Outputs/ocr_output.zip", filename="{}".format(main.allinall(upload_file)) "_output.zip", media_type='application/zip')
在瀏覽器中并在我擁有的 UI 的幫助下,我能夠上傳檔案并下載輸出檔案(回傳...)。
我想在 linux 服務上測驗這個,我必須通過 curl 命令測驗這個 api。我正在使用這個命令:
curl -X 'POST' 'http://localhost/extract_text' -H 'accept: application/json' -H 'Content-Type: multipart/form-data' -F 'file=@demo2_test_imageinput.png;type=application/json'
這是我收到的錯誤:
{"detail":[{"loc":["body","upload_file"],"msg":"field required","type":"value_error.missing"}]}
輸入是當前檔案夾中可用的 png 檔案,輸出將是一個 zip 檔案,作為 allinall 函式的輸出。
當我嘗試這個時:
curl -i -X POST -H "Content-Type: multipart/form-data" -F "data=@demo2_test_imageinput.png" http://localhost/extract_text
我收到此錯誤:
HTTP/1.1 422 Unprocessable Entity
Server: nginx/1.15.12
Date: Thu, 19 May 2022 20:16:44 GMT
Content-Type: application/json
Content-Length: 95
Connection: keep-alive
uj5u.com熱心網友回復:
這是你弄錯的地方。
file=@demo2_test_imageinput.png
根據您的函式 def,您的多部分欄位名稱應該是upload_file
async def create_upload_file(upload_file: UploadFile = File(...))
所以你的 curl 請求必須有引數
upload_file=@demo2_test_imageinput.png
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478945.html
上一篇:找不到ALSA-github操作單元測驗,正確設定env/envvars
下一篇:如何在單元測驗中比較新日期?
