Getting a direct link to a file with the extension in Lumen

I use Lumen and I have an audio file in uploads/videos/. I want to return the url of the exact path (e.g. app.com/videos/one.mp4).

I did the same thing very poorly by putting / {fileName} in the routes, specifying /one.mp4 and removing the extension from String as soon as I get the data (one.mp4). This is bad because I use a plugin that only accepts direct links.

(So, for example, when I take a link from any mp4 link (with extension), it works, but when I try to use it using my method, it doesn’t

I found this example for Laravel, however Lumen does not seem to accept ->where:

Route::get('file/{filename}', 'FileController@getFile')->where('filename', '^[^/]+$');

and

 public function getFile($filename)
 {
  return response()->download(storage_path($filename), null, [], null);
 }

But when I try this in Lumen, I get:

Call the undefined method Laravel \ Lumen \ Application :: where ()

, mp4 . , , url myapi.com/videos/two.mp4 two.mp4, .

( , , two two.mp4.)

: https://v.cdn.vine.co/r/videos/12B2B2092B1284614590713798656_4be40e9deb2.4.1.3029273185552527049.mp4

Update:

Chrome, , - , Lumen? Vine.

$app->get('/player/{filename}', 'PlayerController@show')

public function show ($filename)
{
    $this->playVid($filename, 'videos');
}

public function playVid($filename, $showType)
{
    if (file_exists("../uploads/" . $showType . "/" . $filename)) {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $type = finfo_file($finfo, "../uploads/" . $showType . "/" . $filename);

        header("Content-Type: " . $type);
        readfile("../uploads/" . $showType . "/" . $filename);
    }
}

, Vine? , , type="video/mp4"


: https://stackoverflow.com/questions/34369823/same-video-from-my-api-url-doesnt-work-where-works-from-online-url-from-proj

: , , readFile, . , , . - qaru.site/questions/1618992/...

+4

Source: https://habr.com/ru/post/1618989/


All Articles