Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3641

Trying to send .mp4 file from Flask to Angular client and display it on html page player then

$
0
0

I'm new to angular and flask, so I don't know enough about a lot of things yet. I have a code on the flask that processes the video, then sends it back to the angular client on a get request. The problem arises at the moment when I receive the url, there is a problem with the fact that the video does not appear in the window. The angular function code is as follows

  async displayVideo() {    const filename = 'processed_'+ localStorage.getItem('filename_video');    try {        const response = await this.http.get(`http://localhost:5000/displayvideo/${filename}`, { responseType: 'blob' }).toPromise();        if (response) {          console.log(response);           var url = (window.URL || window.webkitURL).createObjectURL(response);          console.log(url);                  this.videoUrl = url;          console.log(this.videoUrl)    }  }catch{    console.log('SMTH WRONG!');  };}

Html code for my video component

<div><h1>VideoPlayer</h1><video autoplay onloadedmetadata="this.muted = true" width="320" height="240" controls><source [src]="videoUrl" type="video/mp4">      mp4 is not supported by your browser</video>    </div>  

and Flask code for sending file back

@app.route('/displayvideo/<filename>')def display_video(filename):    video_path = f'static/output/{filename}'    return send_file(video_path, as_attachment=True)

I've thought about websockets, but maybe there are some other ways to solve this..I'm trying to display video file but not loading it

I tried to download directly by selecting src=localhost:5000/... but I ran into a problem with CORS, there were still attempts to use the returned url, but apparently it is not the same. Although downloading the file at this url is fine, maybe the problem is in the implementation of the video player?


Viewing all articles
Browse latest Browse all 3641

Trending Articles