![](/img/trans.png)
[英]PHP AWS SDK 3 Error: AWS HTTP error: cURL error 6: Could not resolve host: s3.oregon.amazonaws.com
[英]Aws PHP Sdk 3: S3::putObject(): AWS HTTP error: cURL error 6: Couldn't resolve host 's3.Ireland.amazonaws.com'
我正在尝试使用 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 )
这是我第一次尝试这样做,所以我不太有信心。
通过 AWS 接口上传文件,其 URL 类似于https://s3-eu-west-1.amazonaws.com/my-bucket-name/testFileThroughWeb.jpg
。 因此,它似乎与 AWS SDK 创建的用于 PUT 文件的文件不同(即https://s3.Ireland.amazonaws.com/my-bucket-name/testFile.jpg
)
我想指出的另一件事是我传递给 S3Client 的构造函数的版本。 创建它的实例时,将密钥version
stable
值传递给它,而在存储桶策略中我使用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;
}
这可能是我收到错误的原因? 为什么 S3Client 猜测的主机https://s3.Ireland.amazonaws.com
不正确?
没有像“爱尔兰”这样的 AWS 区域。 亚马逊网站上列出了 S3 的有效区域; 您可能在这里尝试使用的是 EU(爱尔兰),它将在区域参数中表示为eu-west-1
。
也许对你来说晚了,但对其他人来说是新的:
AWS HTTP 错误:cURL 错误 6:无法解析主机 's3.Ireland.amazonaws.com'(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html )错误的含义是您有您的 S3 URL/配置错误。 该服务无法使用您的 URL conf 连接到 S3。
比如我的错误,今天我因为错过了一个 URL 块而面临同样的错误。
除此之外,如果您使用替代 DC; 在他们这边使用 AWS 平台。 您应该询问他们自己的 conf 设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.