尝试使用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';
// %的 的 ** * ** * ** * < / EM> ** * ** * ** * ** * ** * < / EM> ** * ** * ** * * %* / //上传文件到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($响应 - &GT;体); =&GT;
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
)
答案 0 :(得分:5)
您需要在课程初始化后设置区域
// Initialize the class
$s3 = new AmazonS3();
$s3->set_region( AmazonS3::REGION_EU_W1 );
...
答案 1 :(得分:0)
结果是什么:
<?php
print_r($response->body);
这应该会从S3给出正确的错误消息。
答案 2 :(得分:0)
; 替换这部分:
services/s3.class.php
为:
const REGION_US_E1 = 's3.amazonaws.com';