title: How to stream an large file from S3 to a laravel view
body: <p>I have this mostly working but having a tough time finalizing it. </p>
  
  <p>For now I have a simple route:</p>
  
  <pre><code>Route::get('file/{id}/', 'FileController@fileStream')-&gt;name('file');
  </code></pre>
  
  <p>this route connects to an action in the FileController:</p>
  
  <pre><code>public function fileStream($id){
  
      $audio = \App\Audio::where('id', $id)-&gt;first();
  
      $client = S3Client::factory([
          'credentials' =&gt; [
              'key'    =&gt; env('AWS_ACCESS_KEY_ID'),
              'secret' =&gt; env('AWS_SECRET_ACCESS_KEY'),
          ],
          'region' =&gt; env('S3REGION'),
          'version' =&gt; 'latest',
      ]);
  
  
      // Register the stream wrapper from an S3Client object
      $client-&gt;registerStreamWrapper();
  
      if ($stream = fopen('s3://[bucket_name]/'. $audio-&gt;audio_url, 'r')) {
          while (!feof($stream)) {
              echo fread($stream, 1024);
          }
          fclose($stream);
      }    
  }
  </code></pre>
  
  <p>This works to the browser: if I go to a url: /file/1 it looks up the right file, and in a clean browser window I get:</p>
  
  <p><a href="https://i.stack.imgur.com/kL0ra.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kL0ra.png" alt="enter image description here"></a></p>
  
  <p>And then in my view I am trying to output the audio like: </p>
  
  <pre><code>   &lt;audio&gt;
        &lt;source src="{{ url('file', ['id' =&gt; $section-&gt;id]) }}" type="{{ $section-&gt;audio_mime_type}}"&gt;&lt;/audio&gt;
     &lt;/audio&gt;
  </code></pre>
  
  <p>But no player is getting output to the screen.  </p>
  
  <p>TIA</p>