首页 文章

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

提问于
浏览
3

我正在尝试使用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?

1 回答

  • 5

    没有像"Ireland"这样的AWS区域 . S3的有效区域列为on Amazon's web site;您可能尝试使用的是欧盟(爱尔兰),它将在区域参数中表示为 eu-west-1 .

相关问题