Gabriel Marques
Gabriel Marques

Reputation: 161

PHP S3 SDK putObject erro "invalid resource type"

Hi I'm trying to transfer files with the PHP SDK but I receive a "Invalid resource type".

$client = \Aws\S3\S3Client::factory(array(
    'key' => $key,
    'secret' => $secret
));

try {
    $client->putObject(array(
        'Bucket' => 'bucket/uploads/photos',
        'Key' => 'example.jpg',
        'SourceFile' => '/absolute/path/to/example.jpg',
        'ACL' => 'public-read'
    ));
} catch(\Exception $e) {
    echo $e->getMessage();
}

I tested the IAM user with the Amazon policy simulator and the user has access to putObject for that resource.

The SDK version is 2.6.15.

I also tested 'Hello world' in the 'Body' instead of 'SourceFile'. If I use body with plain text it works.

What else can I do?

Upvotes: 1

Views: 1513

Answers (1)

voodoo417
voodoo417

Reputation: 12101

Try through Body :

$client->putObject(array(
    'Bucket' => 'bucket/uploads/photos',
    'Key  ' => 'example.jpg',
    'Body' => fopen('/absolute/path/to/example.jpg','r'),
    'ACL' => 'public-read-write',
    'ContentType' => 'image/jpeg'
));

Upvotes: 1

Related Questions