Amazon S3的SDK PHP doesObjectExist()问题 [英] Amazon S3 SDK PHP doesObjectExist() problems

查看:1644
本文介绍了Amazon S3的SDK PHP doesObjectExist()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重新写了这个问题更清楚,因为我已经更新了。

I've re-written this question to make it clearer, since I've updated it.

我在与亚马逊AWS S3 PHP SDK的麻烦。我只是想检查文件是否存在。 使用这个PHP脚本:

I'm having trouble with the Amazon AWS S3 PHP SDK. I'm just trying to check if a file exists. Using this PHP script:

<?php
    require_once("../../../configs/config.".get_current_user().".php");
    require INCLUDES_PATH . 'libraries/aws/aws-autoloader.php';

    use Aws\S3\S3Client;

    $client = S3Client::factory(array(
          'key' => AWS_ACCESS_KEY_ID,
          'secret' => AWS_SECRET_KEY
      ));

    $key = 'profile/avatar/80745d03-c295-4205-bd82-58161f2fd2d1-320.jpg';
    $result = $client->doesObjectExist( AWS_S3_BUCKET, $key );

    var_dump(AWS_S3_BUCKET);
    var_dump($key);
    var_dump($result);

?>

这是输出:

string(19) "stage.socialite.app"
string(59) "profile/avatar/80745d03-c295-4205-bd82-58161f2fd2d1-320.jpg"
bool(false)

我知道文件的存在,它在这里:

I know the file exists, it's here:

<一个href="http://stage.socialite.app.s3.amazonaws.com/profile/avatar/80745d03-c295-4205-bd82-58161f2fd2d1-320.jpg" rel="nofollow">http://stage.socialite.app.s3.amazonaws.com/profile/avatar/80745d03-c295-4205-bd82-58161f2fd2d1-320.jpg

这是IAM策略对于用户来说,其密钥和安全密钥我使用:

This is the IAM policy for the user, whose Key ID and Secret Key I'm using:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
          "s3:*"
      ],
      "Resource": [
        "arn:aws:s3:::stage.socialite.app/*",
        "arn:aws:s3:::stage.socialite.app"
      ]
    }
  ]
}

我刚刚建立了一个新的密钥/秘密对和他们加入到我的配置 - ?我做了什么错

I've just created a new Key/Secret pair and added them to my config - what have I done wrong?

推荐答案

我发现了另一个SO后的答案,从的卡洛斯·卡斯蒂略的:

I found the answer on another SO post, in a comment from Carlos Castillo:

<一个href="http://stackoverflow.com/questions/15558289/aws-php-sdk-version-2-s3-filename-encoding-issue">AWS PHP SDK版本2 S3文件名编码问题

他指出我在一个 Github上发出的方向的初始化S3客户端时,建议设置区域,这是因为我在爱尔兰使用S3比如我开发服务器,而不是默认美国的服务器。

He pointed me in the direction of a Github Issue that suggested setting the region when initializing the S3 client, this is because I'm using an S3 instance in Ireland for my dev server, not the default US servers.

所以,这是解决方案:

$client = S3Client::factory(array(
    'key' => AWS_ACCESS_KEY_ID,
    'secret' => AWS_SECRET_KEY,
    'region' => AWS_S3_REGION
));

其中, AWS_S3_REGION 是我的配置文件设定的常数,像钥匙和密码。

Where AWS_S3_REGION is a constant set in my config file, like the Key and Secret.

幸得 neilscastle ,卡洛斯和堆栈溢出为它的优秀的搜索引擎优化

Credit goes to neilscastle, Carlos and Stack Overflow for it's excellent SEO

这篇关于Amazon S3的SDK PHP doesObjectExist()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆