Feb 4, 2019
0
Level 1
Downloading file from S3 bucket to local server
Hi,
I'm trying to process a large file that lives in a S3 bucket. I need to download the file locally, process the file, and then upload the file back to the S3 bucket.
This is what I have so far
// Get the file contents
$content = Storage::disk('s3')->get($path . '/' . $originalFileName);
// Save the file locally
Storage::disk('local')->put('tmp/' . $originalFileName, $content);
// Process file logic goes here
// ...
// Save the processed file on S3
Storage::disk('s3')->put($path . '/[unique file name here]', $processedContent);
The problem with this approach is that I'm loading the whole file into memory. This is not an issue when Im dealing with a small file, but once I deal with a Large file (lets say 100mb).
So my question is, how can I copy a file from one disk to another (if possible), if thats not possible, how can I download that file on my server? I know there are many ways in PHP to do this, but I want to achieve this using Laravel's Flysystem.
Any help would be appreciated :)
Please or to participate in this conversation.