Created a python fastapi
endpoint – post
which takes a pdf file
as input does some processing and returns the pdf file
back
from fastapi import FastAPI, status, File, Response
app = FastAPI()
@app.post("/get_file")
def create_item(file_name: str, file_bytes:bytes = File(...)):
# process the file
processed_file_bytes = process(file_bytes)
headers = {'Content-Disposition': 'inline; filename="out.pdf"'}
return Response(processed_file_bytes, headers=headers, media_type='application/pdf')
this works fine when testing via swagger docs
But when I try to test it using requests
import requests
import fitz
file_name = 'sample.pdf'
file_bytes = fitz.open(file_name).tobytes()
payload = {'file_name':file_name, 'file_bytes':file_bytes}
r = requests.post("http://localhost:8000/get_file", params = payload)
Error:
ConnectionError: Connection Aborted. [Errno 10054] An existing connection was forcibly
closed by the remote host, None, 10054, None
Any suggestion will be helpful.