File download: stream response is not working

What seems to be the problem:
I am trying to make a streamed download and got a feeling that streamed download is not supported by Livewire at all.

Steps to Reproduce:
Export large amount of data as a stream:

    return response()->streamDownload(function () use($ids, $filename) {
                    $options = new \ZipStream\Option\Archive();
                    $options->setSendHttpHeaders(false);
                    $zip = new \ZipStream\ZipStream($filename, $options);
                    Media::whereIn('id', $ids)->select('id', 'original_name', 'data')->chunk(10, function($medias) use ($zip){
                        foreach ($medias as $media) {
                              $zip->addFile($media->original_name, $media->data);
                        }
                    });
                    $zip->finish();
                }, $filename);

Are you using the latest version of Livewire:
yes

Hey, @Dimonka2

Any output?

Actually I just got new output: On local machine (localhost) Firefox crashes, if the zip file is huge (I guess it tries to load it into memory).
On remote server request gets interrupted and page reloads.

Have you tried to download simple file (e.g. image) to make that the problem came from the download method not from the zipping process?

It works with a few documents, but if I start to download like over 100MB, then those issues happens. I moved this method to a controller and it is working. The problem of Livewire is that the download first coming to a JS function and loaded into memory. Thus it is not possible to download something big out of Livewire component.

Aha! it make sense now.

I don’t know how but. If there is way to chunk the downloaded data while streaming it, it will be a good idea.

But the simple is good. if you can do it with the normal controller it is a good idea though.

Glade your issue was solved and I learnt something new today from you :slight_smile: