【问题标题】:AWS SDK for PHP's S3 stream wrapper works for writing, but not for readingAWS SDK for PHP 的 S3 流包装器适用于写入,但不适用于读取
【发布时间】:2014-07-16 21:02:45
【问题描述】:

我决定使用 AWS SDK 的包装器,这样我就可以方便地从我的 S3 存储桶中流式传输数据,但情况如下:

使用此代码写入我的存储桶有效

$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);

此操作后文件存在,所以一切正常,但之后我无法读取它,因为fopen('s3://mybucket/test.txt', 'r') 失败并出现以下警告:

Warning: fopen(s3://mybucket/test.txt): failed to open stream: "Aws\S3\StreamWrapper::stream_open" call failed

...还有这个错误:

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

因此,我可以捕获该异常或改用getObject,但我仍然无法读取文件流,这违背了目的。也许这不是什么大事,但我对 Guzzle 和 AWS SDK 的内部工作原理并不熟悉。

任何关于我在这里做错的帮助或指南将不胜感激,我在谷歌上搜索了一段时间,但我找不到有用的信息来解决它,所以这很可能是由于我的无能。

提前致谢。

干杯。

【问题讨论】:

  • 您的意思是从读取的 fopen() 中省略 'r' 参数吗?
  • @MarcB 忘了写在问题里(但它在代码里),感谢观察!

标签: php amazon-web-services amazon-s3 guzzle aws-php-sdk


【解决方案1】:

请尝试在 php.ini 中启用 openssl:

extension=php_openssl.dll

【讨论】:

    猜你喜欢
    • 2021-08-07
    • 1970-01-01
    • 2022-12-17
    • 1970-01-01
    • 2016-04-07
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多