【问题标题】:Cannot Upload Files to existing bucket in s3 SDK PHP无法将文件上传到 s3 SDK PHP 中的现有存储桶
【发布时间】:2013-02-06 01:21:10
【问题描述】:

尝试使用 s3 的 PHP SDK 上传文件。上传文件到已有Bucket,弹出错误。

<?php
error_reporting(-1);
// Set plain text headers
header("Content-type: text/plain; charset=utf-8");
// Include the SDK
require_once '../sdk.class.php';

//%********* *************** **********%*/ // 上传文件到 S3

// Instantiate the AmazonS3 class
$s3 = new AmazonS3();
$s3->path_style = true;

$bucket = 'photossss1.abc.com';

$name = "picture.jpg" ;
$response = $s3->create_object($bucket, 'picture2.jpg', array(
    'fileUpload' => 'picture.jpg'
));

if($response->isOk()){
    echo " Done" ;
} else {
    //var_dump($response);
    echo "error: create_object error.";
}

上面的代码有什么错误..?

调试: print_r($response->body); =>

CFSimpleXML Object
(
    [Code] => PermanentRedirect
    [Message] => The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
    [RequestId] => DACD5C54BC4BD82
    [Bucket] => photossss1.abc.com
    [HostId] => QUBlZEZKh0Ujzk6UyGG7LjC0vMCWDlOPszTZru/+OpWidBH84VXor1 
    [Endpoint] => photossss1.abc.com.s3.amazonaws.com
)

【问题讨论】:

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


    【解决方案1】:

    类初始化后需要设置区域

    // Initialize the class
    $s3 = new AmazonS3();
    $s3->set_region( AmazonS3::REGION_EU_W1 );
    ...
    

    Related page on SDK Documentation

    【讨论】:

      【解决方案2】:

      结果是什么:

      <?php
      print_r($response->body);
      

      这应该会为您提供来自 S3 的正确错误消息。

      【讨论】:

      • print_r($response->body); CFSimpleXML Object ( [Code] =&gt; PermanentRedirect [Message] =&gt; The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. [RequestId] =&gt; DACD5C54BC4BD82 [Bucket] =&gt; photossss1.abc.com [HostId] =&gt; QUBlZEZKh0Ujzk6UyGG7LjC0vMCWDlOPszTZru/+OpWidBH84VXor1 [Endpoint] =&gt; photossss1.abc.com.s3.amazonaws.com )
      • 您要推送到非美国东部端点吗?您是否尝试过明确设置区域? AmazonS3::set_region().
      • 我正在推动在欧盟(爱尔兰)地区创建的存储桶。
      【解决方案3】:

      services/s3.class.php; 替换这部分:

      const REGION_US_E1 = 's3.amazonaws.com';
      

      到:

      const REGION_US_E1 = 's3-eu-west-1.amazonaws.com';
      

      【讨论】:

        猜你喜欢
        • 2018-03-25
        • 2018-08-13
        • 2017-09-24
        • 2018-04-04
        • 1970-01-01
        • 1970-01-01
        • 2012-05-28
        • 2021-07-22
        • 2017-10-17
        相关资源
        最近更新 更多