title: Getting Direct Link of File With Extension in Lumen
body: <p>I am using Lumen and I have an audio file in my <code>uploads/videos/</code>. I want to return the URL of the exact path (like <code>app.com/videos/one.mp4</code>).</p>
  
  <p>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. </p>
  
  <p>(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</p>
  
  <p>I found this example for Laravel, however Lumen apparently doesn't accept <code>-&gt;where</code>:</p>
  
  <pre><code>Route::get('file/{filename}', 'FileController@getFile')-&gt;where('filename', '^[^/]+$');
  
  and
  
   public function getFile($filename)
   {
    return response()-&gt;download(storage_path($filename), null, [], null);
   }
  </code></pre>
  
  <p>But when I try it in Lumen, I receive:</p>
  
  <blockquote>
    <p>Call to undefined method Laravel\Lumen\Application::where()</p>
  </blockquote>
  
  <p>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 <code>myapi.com/videos/two.mp4</code> and play <code>two.mp4</code> as soon as I hit to the link.</p>
  
  <p>(Please note that I store the filename in database without extension, just as <code>two</code> for <code>two.mp4</code>.)</p>
  
  <p>Example link format: <a href="https://v.cdn.vine.co/r/videos/12B2B2092B1284614590713798656_4be40e9deb2.4.1.3029273185552527049.mp4" rel="nofollow noreferrer">https://v.cdn.vine.co/r/videos/12B2B2092B1284614590713798656_4be40e9deb2.4.1.3029273185552527049.mp4</a></p>
  
  <p><strong>Update:</strong></p>
  
  <p>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.</p>
  
  <pre><code>$app-&gt;get('/player/{filename}', 'PlayerController@show')
  </code></pre>
  
  <hr>
  
  <pre><code>public function show ($filename)
  {
      $this-&gt;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);
      }
  }
  </code></pre>
  
  <p>If so, what is the difference between my file &amp; Vine file? When I open both of the videos in browser, right+click and check source, both videos have <code>type="video/mp4"</code></p>
  
  <hr>
  
  <p><em>More information on Question:</em> <a href="https://stackoverflow.com/questions/34369823/same-video-from-my-api-url-doesnt-work-where-works-from-online-url-from-proj">https://stackoverflow.com/questions/34369823/same-video-from-my-api-url-doesnt-work-where-works-from-online-url-from-proj</a></p>
  
  <p><em>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 - <a href="https://stackoverflow.com/a/34435905/4705339">https://stackoverflow.com/a/34435905/4705339</a></em></p>