'Return File/Stream response from googlevideo in Fast API

I am using Fast API to return a video response from googlevideo.com. This is the code I am using:

@app.get(params.api_video_route)
async def get_api_video(url=None):

  def iter():
     req = urllib.request.Request(url)

     with urllib.request.urlopen(req) as resp:
         yield from io.BytesIO(resp.read())


  return StreamingResponse(iter(), media_type="video/mp4")

but this is not working

I want this Nodejs to be converted into python FAST API:

app.get("/download-video", function(req, res) { 
 http.get(decodeURIComponent(req.query.url), function(response) { 
   res.setHeader("Content-Length", response.headers["content-length"]); 
   if (response.statusCode >= 400)         
     res.status(500).send("Error");                     
     response.on("data", function(chunk) { res.write(chunk); }); 
     response.on("end", function() { res.end(); }); }); });


Solution 1:[1]

Use the below instead, as described in the documentation here.

#yield from io.BytesIO(resp.read())
yield from resp

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris