aws s3 php host,Aws PHP Sdk 3:S3 :: putObject():AWS HTTP错误:cURL错误6:无法't resolve host ' s3.Ireland.am...

我正在尝试使用SDK的版本3将图像上传到S3存储桶,但是我收到以下错误:

在“https://s3.Ireland.amazonaws.com/my-bucket-name/testFile.jpg”上执行“PutObject”时出错; AWS HTTP错误:cURL错误6:无法解析主机's3.Ireland.amazonaws.com'(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html)

这是我第一次尝试这样做,所以我不太自信 .

Uploading a file through the AWS interface, its URL is something like https://s3-eu-west-1.amazonaws.com/my-bucket-name/testFileThroughWeb.jpg. So, it seems to be different from the one created by the AWS SDK to PUT the file (that is https://s3.Ireland.amazonaws.com/my-bucket-name/testFile.jpg)

Another thing I'd like to point out is the version I pass to the constructor of S3Client. Its instance is created passing to it the value stable for the key version while in the bucket policy I use version: "2012-10-17".

这是存储桶策略的配置:

{

"Version": "2012-10-17",

"Statement": [

{

"Sid": "AddPerm",

"Effect": "Allow",

"Principal": {

"AWS": "*"

},

"Action": "s3:*",

"Resource": "arn:aws:s3:::my-bucket-name/*"

}

]

}

要将图像保存在存储桶中,我使用以下代码:

public function testS3Action()

{

$fileToUpload = 'http://example.com/an/image.jpg';

// Get the remote file extension

$remoteImageExtension = explode('.', $fileToUpload);

$remoteImageExtension = array_pop($remoteImageExtension);

$fs = new Symfony\Component\Filesystem\Filesystem();

$tempImage = tempnam(sys_get_temp_dir(), 'image.') . '.' . $remoteImageExtension;

/**

* From the Symfony container

* @var GuzzleHttp\Client $client

*/

$client = $this->get('guzzle.client');

// Get and save file

$client->get($fileToUpload, ['save_to' => $tempImage]);

$tempImage = new Symfony\Component\HttpFoundation\File\File($tempImage);

/**

* From the Symfony container

* @var Aws\S3\S3Client $s3

*/

$s3 = $this->get('shq.amazon.s3');

$params = [

'Bucket' => $this->getParameter('amazon.s3.bucket'),

'Key' => 'testFile.jpg',

'Body' => $tempImage

];

$result = $s3->putObject($params);

return $result;

}

Which could be the cause of the error I'm getting? Why the host https://s3.Ireland.amazonaws.com guessed by the S3Client isn't correct?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值