-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[FEATURE] Ability to stream to an Amazon S3 bucket #2326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I usually like to see a unit test demonstrating that the change works. However, such a test seems impractical here - it requires access to s3, which probably introduces security and availability challenges. It seems clear to me that the change will have no adverse effect for non-s3 access. |
Of course, you could refactor a little more. Example: There is a function setModeForFileHandle() There one could test also without S3 package dependency simply whether the scheme changes. For future changes e.g. further PHP wrapper this would be surely also more suitable. What do you think? |
This change makes a lot of sense! Looking forward for it getting merged! |
Thank you for your contribution. |
BaseWriter openFileHandle opens its output file with mode `wb+`. We don't appear to attempt any reads on the file after it is opened in write mode, so `wb` should be sufficient. This may have been a factor in the need for PR PHPOffice#2326, and is likely to be responsible for issue PHPOffice#2372.
I think s3:// would work in much the same way as http://. Unfortunately, http:// doesn't work for read. It will fail in However, the following code may be useful to you (substitute your own s3 filename - I have no way to test that): $filename = 'http://localhost:8000/filename.xlsx';
$contents = file_get_contents($filename);
$tmpfile = tmpfile();
$path = stream_get_meta_data($tmpfile)['uri'];
echo "path is $path\n";
fwrite($tmpfile, $contents);
fseek($tmpfile, 0);
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($path);
fclose($tmpfile); The temporary file should be deleted by the fclose, and you can always write some sort of handler to force its deletion even if the spreadsheet load fails. |
Related #2249
This is:
Requirements
composer required aws/aws-sdk-php
Example