Is there a way to use FastAPI StreamingResponse with bytes like object?

1.2k Views Asked by At

In FastApi the below code is used to stream large files

def iterfile(file_name):  #
        with open(file_name, mode="rb") as file_like:  #
            yield from file_like  #

    return StreamingResponse(iterfile(file_), media_type="application/pdf")

However is I dont have the file saved. I have assigned it as variable of type(class 'bytes') Is there a possible way I could use StreamingResponse with the binary file saved as variable instead of a file.

0

There are 0 best solutions below