Reputation: 6814
I used aws sdk (https://github.com/aws/aws-sdk-php).
code
$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => $key,
'Body' => $file,
'ACL' => 'public-read',
));
It's work well but i have a question:
Thanks.
Upvotes: 11
Views: 23544
Reputation: 61
The result returned is an instance of Guzzle\Service\Resource\Model.
To get the url just use the get method provided by that class.
$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => $key,
'Body' => $file,
'ACL' => 'public-read',
));
$url = $result->get('ObjectURL');
Upvotes: 6
Reputation: 2044
The object URL is available in the $result
variable that is returned in your function call.
To access the object URL do this:
$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => $key,
'Body' => $file,
'ACL' => 'public-read',
));
$data=$result->toArray();
$object_url=$data['ObjectURL'];
Upvotes: 2
Reputation: 6527
It is returned in the response. See the API docs for putObject.
$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => $key,
'Body' => $file,
'ACL' => 'public-read',
));
$url = $result['ObjectURL'];
You can also use the getObjectUrl()
method to get the URL.
$url = $client->getObjectUrl($bucket, $key);
Upvotes: 25