Closed jixt closed 11 years ago
The error was due to not using 'default_settings' in aws-config.php (which is in my case) ,and in default when initiating a service , it always uses 'default_settings' along with default prefix (A2Base.php constants-> line no.20-41) for specific service . So in your case 's3' , if i defined a custom prefix in in aws-config.php (say 'v2.s3' -http://bit.ly/ZpPgtS) , then script will throw above error.
So i did some minor code modification to overcome this ,
Sample code modification :
A2base.php -> http://pastebin.com/2KATfvYD A2S3.php -> http://pastebin.com/cCh2RafN aws-config.php ->http://pastebin.com/R7qREHKq Sample Code (list buckets in s3)->http://pastebin.com/24dzkJQA
@jixt If calling the method directly doesn't work, please make use of your classname->getClient()->listBuckets()
I am tracking down that error
@tonydspaniard @Code-BlUe I am getting error like the following " Error retrieving credentials from the instance profile metadata server. When you are not running inside of Amazon EC2, you must provide your AWS access key ID and secret access key in the "key" and "secret" options when creating a client or provide an instantiated Aws\Common\Credentials\CredentialsInterface object."
Thanks
@randmuhtaseb did you setup your credentials at the config file?
Edit: I am using this extension on a current project without any issues at all
@tonydspaniard Yes, and i am implementing Code-BlUe changes, because i got this error "A2S3 and its behaviors do not have a method or closure named "listBuckets"" before.
@randmuhtaseb just found the issue... please, update on the following commit
Working example code:
Yii::import('common.extensions.amazon.components.*');
$s3 = new A2S3();
$objects = $s3->listObjects(array('Bucket' => Yii::app()->params['aws.bucket']));
foreach ($objects->get('Contents') as $object)
print('<p>' . $object['Key']) . '</p>';
I am getting now "The difference between the request time and the current time is too large."
Thanks @tonydspaniard
@randmuhtaseb thats not from the extension (btw update again your repository)
Here your solution http://stackoverflow.com/questions/4770635/s3-error-the-difference-between-the-request-time-and-the-current-time-is-too-la
@tonydspaniard Oh that solved the problem, and it was because my time is out of sync with the current time. Thanks a lot for your help, i appreciate it :)
@tonydspaniard I am trying to upload large files using multipart uploads using uploadBuilder, but when i add this to my code, it gives me parsing errors :
use Aws\Common\Enum\Size; use Aws\Common\Exception\MultipartUploadException; use Aws\S3\Model\MultipartUpload\UploadBuilder;
what should i do to solve it? and can you give me example of using "createMultipartUpload" method?
Thanks in advance
hey @randmuhtaseb sure:
/**
* Helper function to perform multipart uploads of large files
* @param $source
* @param $bucket
* @param $key
* @return bool
*/
public function multipartUpload($source, $bucket, $key)
{
$uploader = Aws\S3\Model\MultipartUpload\UploadBuilder::newInstance()
->setClient($this->getClient())
->setSource($source)
->setBucket($bucket)
->setKey($key)
->setMinPartSize(5 * Aws\Common\Enum\Size::MB)
->build();
try
{
$dispatcher = $uploader->getEventDispatcher();
$dispatcher->addListener($uploader::BEFORE_UPLOAD, function ($event) {
echo "About to start uploading parts.\n";
});
$dispatcher->addListener($uploader::AFTER_UPLOAD, function ($event) {
echo "Finished uploading parts.\n";
});
$dispatcher->addListener($uploader::BEFORE_PART_UPLOAD, function ($event) {
$partNumber = $event['command']->get('PartNumber');
$size = $event['command']->get('Body')->getContentLength();
echo "About to upload part {$partNumber}, which is {$size} bytes.\n";
});
$dispatcher->addListener($uploader::AFTER_PART_UPLOAD, function ($event) {
$partNumber = $event['command']->get('PartNumber');
$eTag = $event['command']->getResult()->get('ETag');
echo "Finished uploading part {$partNumber}, which has an ETag of {$eTag}.\n";
});
$dispatcher->addListener($uploader::AFTER_COMPLETE, function ($event) {
echo "Upload completed.\n";
});
$dispatcher->addListener($uploader::AFTER_ABORT, function ($event) {
echo "Upload aborted.\n";
});
$uploader->upload();
} catch (Aws\Common\Exception\MultipartUploadException $e)
{
$uploader->abort();
return false;
}
return true;
}
just a side note : when you define namespaces in a class , you are not allowed define inside the class (php.net/manual/en/language.namespaces.importing.php#language.namespaces.importing.scope)
@VoBB-Technologies but I am not importing use
, just being lazy to import the classes on top, just calling the class directly using the long path... but not defining the namespace within.
PS: Did it workout for you?
@tonydspaniard : yes it worked for me :+1: . I test this before . didn't follow this thread much , else i would have commented . the trick was to pass a s3 connection instance without any methods calling in ->setClient()
eg:
use Aws\S3\Model\MultipartUpload\UploadBuilder;
$s3->new A2S3();
UploadBuilder::newInstance()
->setClient($s3->getClient()) //this is the part need to consider
->setSource($source)
->setBucket($bucket)
->setKey($key)
->setMinPartSize(5 * Aws\Common\Enum\Size::MB)
->build();
@VoBB-Technologies yes, you are right... apologies as I was including the method within the A2S3
class on one of my projects...
Thank you!
Hi,
I'm trying to call listObjects, isValidBucketName, but none of them are working. I always get the following error:
A2S3 and its behaviors do not have a method or closure named "isValidBucketName".
Is it possible to give more examples? thx!
JR