繁体   English   中英

无法将文件上传到s3 SDK PHP中的现有存储桶

[英]Cannot Upload Files to existing bucket in s3 SDK PHP

尝试使用s3的PHP SDK上传文件。 将文件上传到现有存储桶时,会弹出错误。

<?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
)

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

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

SDK文档的相关页面

结果是什么:

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

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

services/s3.class.php 替换此部分:

const REGION_US_E1 = 's3.amazonaws.com';

至:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM