dimanche 2 août 2015

Aws PHP Sdk 3: S3::putObject(): AWS HTTP error: cURL error 6: Couldn't resolve host 's3.Ireland.amazonaws.com'

I'm trying to upload an image to an S3 bucket using the version 3 of the SDK, but I receive the following error:

Error executing "PutObject" on "http://ift.tt/1OYjH3y"; AWS HTTP error: cURL error 6: Couldn't resolve host 's3.Ireland.amazonaws.com' (see http://ift.tt/1mgwZgQ)

This is the first time I try to do this, so I'm not much confident.

Uploading a file through the AWS interface, its URL is something like http://ift.tt/1OYjJsc. So, it seems to be different from the one created by the AWS SDK to PUT the file (that is http://ift.tt/1OYjH3y)

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".

This is the configuration of the bucket policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::my-bucket-name/*"
        }
    ]
}

To save the image in the bucket, I use this code:

public function testS3Action()
{
    $fileToUpload = 'http://ift.tt/1ISJs6o';

    // 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 http://ift.tt/1ISJqeN guessed by the S3Client isn't correct?




Aucun commentaire:

Enregistrer un commentaire