I am trying to write endpoint for image uploading, it will accept just image in base64 format. I have read how to get file from request in FastAPI and implement that in this way:
server side
@router.post("/v1/installation/{some_identifier}/image")
@db.create_connection
async def upload_installation_image(some_identifier: int, data: UploadFile = File(...)):
...
content = await data.read()
image_uuid = await save_image(installation.uuid, content, data.content_type)
return {"image_uuid": image_uuid}
And its works fine, but in this case I need to send data in this way:
client side
def test_upload_image(...):
...
response = session.post(
f"/v1/installation/{relink_serial}/image", files={"file": ("test_file_name.png", data, "image/png")}
)
...
But I want to be able to upload image like this:
client side
def test_upload_image(...):
...
response = session.post(
f"/v1/installation/{installation_uuid}/image", data=data, headers={"content-type": "image/png"}
)
I have read a lot of articles and other questions, but all of them suggest to use UploadFile and send data as json with file
or body
parameter.
Is this even possible, to load just 1 file like in second test I show?