How to save file when using Storage::readStream() ?
I want to download a large file via google driver like:
$stream = Storage::disk('google')->readStream('large-file.zip');
// how to save this to a local file ?
It return stream resource as output, So how to save this in local disk as zip file ?
What do you do with $stream?
@Sinnbeck It's my question it return stream output into $stream variable, So how do i save this as file ?
@untymage not at a computer now but how about
$stream = Storage::disk('google')->readStream('large-file.zip');
Storage::disk('local')->writeStream('/path/large-file.zip', $stream);
@Sinnbeck Allowed memory size of 536870912 bytes exhausted (tried to allocate 4173332
80 bytes)
@untymage yeah I assume it reads it into memory. It might be better with a clean copy job. I'll check to see if there is a built in method
Try
Storage::disk('local')->put(
'large-file.zip',
Storage::disk('google')->get('large-file.zip'));
@Sinnbeck same error Allowed memory size of 536870912 bytes exhausted (tried to allocate 648091640 bytes)#0 {main}
@untymage are you running this in an artisan command?
@untymage currently my only suggestion is to try and increase max memory to 1024 mb which I would assume is the steam size
With the stream you can also try closing the stream
$stream = Storage::disk('google')->readStream('large-file.zip');
Storage::disk('local')->writeStream('/path/large-file.zip', $stream);
fclose($stream);
Please or to participate in this conversation.