I am using Lumen and I have an audio file in my uploads/videos/
. I want to return the URL of the exact path (like app.com/videos/one.mp4
).
I have achieved same thing in a very bad-practiced way by putting /{fileName} in routes, giving /one.mp4 and by removing the extension from String as soon as I receive the data (one.mp4). This is a bad way because I'm using a plugin that only accepts direct links.
(So for example, when I take link from any mp4 link (with extension), it works, but when I try it with my method, it doesn't
I found this example for Laravel, however Lumen apparently doesn't 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 it in Lumen, I receive:
Call to undefined method Laravel\Lumen\Application::where()
What is the way of setting a route that receives filename with extension as parameters and returns the mp4 file in directory. So basically, I want to hit url myapi.com/videos/two.mp4
and play two.mp4
as soon as I hit to the link.
(Please note that I store the filename in database without extension, just as two
for two.mp4
.)
Example link format: https://v.cdn.vine.co/r/videos/12B2B2092B1284614590713798656_4be40e9deb2.4.1.3029273185552527049.mp4
Update:
This below chunk plays the audio in Chrome but not the app, may it be because of the app itself rather than Lumen? But it's playing successfully the above Vine link.
$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);
}
}
If so, what is the difference between my file & Vine file? When I open both of the videos in browser, right+click and check source, both videos have type="video/mp4"
More information on Question: https://stackoverflow.com/questions/34369823/same-video-from-my-api-url-doesnt-work-where-works-from-online-url-from-proj
Update: I realised my problem was caused because I was using readFile, but I wanted to use streaming. If you believe that's the problem, refer here - https://stackoverflow.com/a/34435905/4705339