Coverage for docs_src/custom_response/tutorial008.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import FastAPI 1abcde

2from fastapi.responses import StreamingResponse 1abcde

3 

4some_file_path = "large-video-file.mp4" 1abcde

5app = FastAPI() 1abcde

6 

7 

8@app.get("/") 1abcde

9def main(): 1abcde

10 def iterfile(): # (1) 1abcde

11 with open(some_file_path, mode="rb") as file_like: # (2) 1abcde

12 yield from file_like # (3) 1abcde

13 

14 return StreamingResponse(iterfile(), media_type="video/mp4") 1abcde