【问题标题】:AWSSDK S3 - if_object_exists keeps returning false when file does existAWSSDK S3 - if_object_exists 在文件确实存在时不断返回 false
【发布时间】:2013-04-05 11:14:25
【问题描述】:

我目前正在使用以下代码:

include 'lib/sdk.class.php';
$s3 = new AmazonS3();
$bucket = 'mybucket'.strtolower($s3->key);
$key = 'myfile.txt';
$response = $s3->if_object_exists($bucket,$key);

但是当文件确实存在时,$response 总是返回 false,是我遗漏了什么吗?

【问题讨论】:

    标签: php amazon-web-services amazon-s3 file-exists


    【解决方案1】:

    如果文件确实存在并且可以访问,那么这个函数应该返回 true。我会尝试通过执行以下操作将 SDK 置于调试模式:

    $s3->enable_debug_mode(true);
    

    这会打开CURL_VERBOSE 输出,并且您应该能够在执行代码时查看到 S3 的实际 HTTP 请求和响应。这应该可以帮助您弄清楚可能出了什么问题。在此之后,如果您认为存在错误,您可以在 GitHub 上为 SDK 提交问题,地址为 https://github.com/amazonwebservices/aws-sdk-for-php/issues

    【讨论】:

      【解决方案2】:

      在到处乱七八糟的代码之后,我查看了我之前创建的其他站点的一些 S3 调用,并比较了这些调用是如何完成的。我注意到我以前的代码没有使用以下代码:

      $bucket = 'mybucket'.strtolower($s3->key);
      

      我使用的是:

      $bucket = 'mybucket';
      

      最终代码如下所示:

      include 'lib/sdk.class.php';
      $s3 = new AmazonS3();
      $bucket = 'mybucket';
      $key = 'myfile.txt';
      $response = $s3->if_object_exists($bucket,$key);
      

      这最终奏效了。但是,我不知道为什么这适用于amazon 提供的示例。

      【讨论】:

      • 这个解决方案也适用于我,但我不知道为什么。
      猜你喜欢
      • 2014-01-26
      • 2011-07-23
      • 2011-10-19
      • 2017-08-16
      • 2016-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      相关资源
      最近更新 更多