1

尝试使用 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
)
4

3 回答 3

5

您需要在类初始化后设置区域

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

SDK 文档的相关页面

于 2013-02-05T17:21:10.020 回答
0

结果是什么:

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

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

于 2012-10-05T05:53:17.010 回答
0

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

const REGION_US_E1 = 's3.amazonaws.com';

至:

const REGION_US_E1 = 's3-eu-west-1.amazonaws.com';
于 2012-11-14T12:50:31.597 回答