last day (14 days later) » 

8:59 AM
0
A: Amazon s3 SDK for php can not get Bucket object list

urfusiontry this <?php require 'aws-autoloader.php'; $credentials = new Aws\Credentials\Credentials('XXXXXXXXXXXXX', 'XXXXXXXXXXXXXX'); $bucket = ""; $s3 = \Aws\S3\S3Client::factory([ 'signature' => 'v4', 'version' => 'latest', 'region' => 'ap-southeast-1', 'credentials' => $credentials...

 
code I provided is only of 38 lines. can you tell me what is causing is error? which variable or condition?
 
Parse error: syntax error, unexpected '[', expecting ')' in /home/public_html/i.php on line 6
 
are you using AWS SDK? if yes then which version?
 
are you using the same code as provided by me or using it with you own code?
here is the documentation which also working same as my code.docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/…
 
8:59 AM
I am getting error $s3 = new Aws\S3\S3Client(['version' => 'latest','region' => 'ap-southeast-1','credentials' => $credentials]);
 
where is your aws-autoloader.php
 
i am using require 'php_plugins/aws/v2/aws-autoloader.php';
 
v2 is for version 2 of aws sdk
do one thing
 
no It just name of folder.
yes tell me
 
down load the sdk from where the link I provided in answer
and use my code as it is
I faced same issue a while ago
 
9:08 AM
can you give me a zip link?
 
ok i am uploding.
 
ok
 
9:36 AM
still same error.
 
send me your whole code
 
<?php
$HOST = 's3.amazonaws.com';

require 'php_plugins/aws/v2/aws-autoloader.php';
$credentials = new Aws\Credentials\Credentials('xxxx', 'xxxx');
$s3 = new Aws\S3\S3Client(['version' => 'latest','region' => 'ap-southeast-1','credentials' => $credentials]);
try {
$objects = $s3->getIterator('ListObjects', array(
'Bucket' => $bucket //bucket nam
));

echo "Keys retrieved!\n";
foreach ($objects as $object) {
echo $object['Key'] . "\n";
}
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
 
9:51 AM
what is the permission of aws-autoloader.php?
 
change it to 664
 
done but same error
 
try to hit aws-autoloader.php by url
 
10:01 AM
yes
are you using htaccess?
 
disable that for a moment
and try again
 
still show error
 
autoloader not executing
that's why you are facing all the errors
check the permission of php_plugins/aws/v2/
all these folders
 
all have 755
 
10:05 AM
php_plugins
 
create a file inside v2
and try to access that
if you succeed in that
all will be fine
you are using shared hosting or dedicated hosting?
 
yes
working fine
i have shared hosting
 
file inside v2 is working fine?
 
yes i have index.php file
 
10:09 AM
there are other folders too inside v2 like Aws,GuzzleHttp etc
what is the permission of them?
 
all folder have 755
in aws-autoloader.pjp have mapping array
Aws\AutoScaling\AutoScalingClient' => __DIR__ . '/Aws/AutoScaling/AutoScalingClient.php',
 
yes
what is the permission of all other folders?
 
755
i change name of file and it show nothing.
and accessible
but on i.php it still show error
 
which php version you are using
it should higher then 5.2
curl is enable on your server?
 
5.3
yes
when i was using this in localhost
it say
Fatal error: Class 'Aws\Credentials\Credentials' not found in
 
10:30 AM
seems a huge issue
I will getback to you
 
sure
thanks for your help.
 
welcome :)
 
well I was also in Jaipur before 3 year ago
 
great
in which company?
and try to phpinfo
check for curl
I think file name is incorrect
awsautoloader.php
while in your code
require 'php_plugins/aws/v2/aws-autoloader.php';
 
i was study there in YIT.
 
10:40 AM
batch?
 
2008-2012
 
ok
I am 2006-2010 batch from IET Alwar
 
ok good to know.
 
:)
 
I have changed file name
while in your code
require 'php_plugins/aws/v2/awsautoloader.php';
 
10:43 AM
so your code has awsautoloader or aws-autoloader?
 
awsautoloader.php
can you check i have show phpinfo,
 
11:06 AM
you can remove now
 
check you have 'Aws\Credentials\Credentials'
<?php
namespace Aws\Credentials;

/**
* Basic implementation of the AWS Credentials interface that allows callers to
* pass in the AWS Access Key and AWS Secret Access Key in the constructor.
*/
class Credentials implements CredentialsInterface
{
private $key;
private $secret;
private $token;
private $expires;

/**
* Constructs a new BasicAWSCredentials object, with the specified AWS
* access key and AWS secret key
*
* @param string $key AWS access key ID
* @param string $secret AWS secret access key
 
no we have
Aws\Common\Credentials\Credentials
 
ok
 
$s3 = new Aws\S3\S3Client(['version'=>'latest', 'region' => 'ap-southeast-1', 'credentials' => $credentials ]);
error in this line
 
11:18 AM
yup
remove this line
 
ok
done
 
$s3 = S3Client::factory(array(
'credentials' => array(
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
),
));
use this
and print $s3
and pass 'signature' => 'v4',
'version' => 'latest',
'region' => 'ap-southeast-1',
as a array
$s3 = S3Client::factory(array(
'credentials' => array(
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
),
'signature' => 'v4',
'version' => 'latest',
'region' => 'ap-southeast-1',
));
try to run $result = $s3->listBuckets();
foreach ($result['Buckets'] as $bucket) {
// Each Bucket value will contain a Name and CreationDate

echo $bucketName = $bucket['Name'];
}
 
ok
show error
 
what error?
 
Catchable fatal error: Argument 1 passed to Aws\Common\Client\AbstractClient::__construct() must implement interface Aws\Common\Credentials\CredentialsInterface, array given, called in /home/fireondo/public_html/i.php on line 8 and defined in /home/fireondo/public_html/php_plugins/aws/v2/Aws/Common/Client/AbstractClient.p‌​hp on line 73
 
11:33 AM
show your code
 
require 'php_plugins/aws/v2/awsautoloader.php';
$credentials = new Aws\Common\Credentials\Credentials("AKIAJLZNOLLR4IW6YOOQ", "8Efvg54PHr+ORJvu/kCj7yEqEXjhRhOgqR2SECZ/");
$s3 = new Aws\S3\S3Client(array('credentials' => $credentials,'signature' => 'v4', 'version' => 'latest', 'region' => 'ap-southeast-1'));
print_r($result = $s3->listBuckets());
 
11:45 AM
Aws\Result Object ( [data:Aws\Result:private] => Array ( [Buckets] => Array ( [0] => Array ( [Name] => pics.glowstaronline.com [CreationDate] => Aws\Api\DateTimeResult Object ( [date] => 2015-09-18 09:28:38 [timezone_type] => 2 [timezone] => Z ) ) [1] => Array ( [Name] => www.glowstaronline.com [CreationDate] => Aws\Api\DateTimeResult Object ( [date] => 2015-09-18 09:59:45 [timezone_type] => 2 [timezone] => Z ) ) ) [Owner] => Array ( [DisplayName] => info [ID] => 4a1f3c382bb0ccefc8c77d60faa3b9bbd382df493cb4e25120c545c1b9b938b8 ) [@metadata] => Array ( [statusCode] => 200 [effectiveUri] => h
<?php
//require 'aws-autoloader.php';

$credentials = new Aws\Credentials\Credentials("AKIAJLZNOLLR4IW6YOOQ", "8Efvg54PHr+ORJvu/kCj7yEqEXjhRhOgqR2SECZ/");
$bucketName = "";
$s3 = \Aws\S3\S3Client::factory([
'signature' => 'v4',
'version' => 'latest',
'region' => 'ap-southeast-1',
'credentials' => $credentials,
'http' => [
'verify' => '/home/ubuntu/cacert.pem'
],
'Statement' => [
'Action ' => "*",
],
// 'debug' => [
// 'logfn' => function ($msg) {
// echo $msg . "\n";
// },
there is something you missing
I use for keys
and see the above output
successfully connected to your bucket
sorry for using you keys
 
ok no problem I will change later.
Let me try code
 
yup
 
did you try form localhost
or any server?
 
I tried on my AWS ec2 machine
 
because on my server it show error
Parse error: syntax error, unexpected '[', expecting ')' in /home/fireondo/public_html/i.php on line 6
 
11:48 AM
do one thing
ask your hosting provider to update your php
 
I thing it only access by SSL
 
I forgot
you need
 
update your php too
 
ok
what charge of EC2?
is this your page
 
 
1 hour later…
1:20 PM
no
 

last day (14 days later) »