Reputation: 111
I decided to use the AWS SDK's wrapper so I could stream data from my S3 bucket for convenience, but the situation is as follows:
Writing to my bucket with this code works
$client = \Aws\Common\Aws::factory(array(
'key' => 'my key',
'secret' => 'my secret',))
->get('S3');
$client->registerStreamWrapper();
$fh = fopen('s3://mybucket/test.txt','w');
fwrite($fh, 'Test');
fclose($fh);
The file exists after this operation, so it's all OK, but I can't read it afterwards since fopen('s3://mybucket/test.txt', 'r')
fails with the following warning:
Warning: fopen(s3://mybucket/test.txt): failed to open stream: "Aws\S3\StreamWrapper::stream_open" call failed
... And this error:
Fatal error: Uncaught exception 'Guzzle\Common\Exception\RuntimeException' with message 'Error creating resource. [type] 2 [message] fopen(https://mybucket.s3.amazonaws.com/test.txt): failed to open stream: Invalid argument [file] phar://path/to/aws.phar/Guzzle/Stream/PhpStreamRequestFactory.php [line] 217' in phar://path/to/aws.phar/Guzzle/Stream/PhpStreamRequestFactory.php on line 271
So, I could catch that exception or use getObject
instead but I still wouldn't be able to read the file stream, which defeats the purpose. Perhaps it's not a huge matter, but I'm not familiar with the inner workings of Guzzle and the AWS SDK.
Any help or guides on what I'm doing wrong here will be greatly appreciated, I googled the issue for a while, but I couldn't find useful information to solve it, so it's likely that this is all happening due to my sheer incompetence.
Thanks in advance.
Cheers.
Upvotes: 1
Views: 2335