Utilizing
Other Advanced Features
304
media_type="image/jpeg")
• The
StreamingResponse
type is also effective in rendering videos in various formats such
as
MP4
. The following service reads a file inside
the application named
sample.mp4
and
publishes it to the browser:
@router.get("/restaurant/upload/video")
def video_presentation():
file_path = os.getcwd() + '\\files\\sample.mp4'
def load_file():
with open(file_path, mode="rb") as video_file:
yield from video_file
return
StreamingResponse(load_file(),
media_type="video/mp4")
• If the service wants to publish a simple HTML markup page without
making references to static
CSS
or JavaScript files, then
HTMLResponse
is the right choice. The following
service renders
an HTML page with a Bootstrap framework provided by some CDN libraries:
Chia sẻ với bạn bè của bạn: