1

I'm using Flysystem in a Symfony app to manage files upload / download on S3.

$downloadableFileStream = $this->get("filesystem")->readStream($document->getDocument()),
$mimeType = $this->get("filesystem")->getMimetype($document->getDocument()),
$filename =$document->getDocument()

if (ob_get_level()) ob_end_clean();
return new StreamedResponse(function () use ($downloadableFileStream, $mimeType, $filename) {
    fpassthru($downloadableFileStream);
}, 200, [
    'Content-Transfer-Encoding', 'binary',
    'Content-Type' => "application/octet-stream",
    'Content-Disposition' => ('attachment; filename="' . $filename . '"'),
    'Content-Length' => fstat($downloadableFileStream)['size'],
]);

It's really slow for large files, i was thinking using stream does not put all file in memory, maybe i'm doing something wrong ? (i have the same problem with upload, i'm using putStream).

The download is instant for small files, but for large files, it seems the complete file is loaded in the filesystem before launch download.

Is there any way to "start" the download not get the entiere file ?

Any suggestions ?

Thanks :)

Benjamin B.
  • 473
  • 5
  • 15

1 Answers1

0

try to add flush(); after fpassthru($downloadableFileStream);

so it will look like

fpassthru($downloadableFileStream);
flush();

Also you don't need $mimeType and $filename in use

Denis Alimov
  • 2,861
  • 1
  • 18
  • 38