amazon web services - AWS SDK for PHP's S3 stream wrapper works for writing, but not for reading

870

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 sincefopen('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 usegetObject 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.

100

Answer

Solution:

Please try to enable openssl in php.ini:

extension=php_openssl.dll

People are also looking for solutions to the problem: php - Installation of Indefero under ubuntu

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.