-2

I have a web application focused around playing videos. It uses a flask api to serve the metadata. I want to be able to pass a local filepath for a video to the client and allow the client to play that video. Since you can't just load a local file, how can I serve the file to the browser? I know there is simplehttpserver but I have files all over the place.

How can I set it up so that I can use the vlc plugin like in this post Open video stream on VLC Player through the browser?

UPDATE

This is not a duplicate. I am asking how can I serve a file from a client-supplied filepath. This can be any location, not just one directory of static css/html/js files I want served. Since the client is getting the filepath from the server, I can validate that file is allowed to be served.

UPDATE 2

Still do not believe this is a duplicate as it is for consumption by a specific plugin, vlc web plugin. I tried to use send_from_directory but it did not work. Hopefully this makes it clearer. If send_from_directory` is the right thing to use though, what is my error here?

On python my endpoint is as follows (using flask-restful):

from flask import Blueprint, send_from_directory
from flask_restful import Api, Resource

class VideoServer(Resource):

    def get(self, filepath):
        path, file = os.path.split(filepath)
        return send_from_directory(path, file)

base_blueprint.add_resource(VideoServer, '/video_server/<string:filepath')   

On the js side:

let videourl = config.api_server + '/video_server/' + filepath
let $video = $("<object>", {type: "application/x-vlc-plugin", data: videourl});
let $param = $("<param>", {name: "movie", value: videourl});
let $embed = $("<embed>", {type: "application/x-vlc-plugin", autoplay: "yes", loop: "no", target: videourl});
$video.append($param);
$video.append($embed);
$("#mydiv").append($video);
$("#mydiv").load();
Community
  • 1
  • 1
postelrich
  • 3,274
  • 5
  • 38
  • 65

1 Answers1

0

For this kind of task I'd recommend a real server (as opposite to python simplehttpserver or flask embedded dev server).

So, maybe nginx ?

Loïc
  • 11,804
  • 1
  • 31
  • 49
  • Well the problem is that the list of video files is dynamic based on user input and a real server has a static configuration – postelrich Jun 30 '16 at 03:45
  • you could have nginx serving files from a folder, and create a symbolic link in that folder to the video file dynamically – Loïc Jun 30 '16 at 14:46
  • i could but that is not very robust if i want to distribute this application cross-platform. Would that become a headache if they already have nginx running separately? – postelrich Jul 01 '16 at 03:00