douping3891
2015-04-21 14:26
浏览 89
已采纳

无法使用Gaufrette和Symfony2检查Amazon s3存储桶是否存在

Getting this error when trying to upload a file to my bucket using VichUploader, Gaufrette and the AWS SDK v2 on a Symfony2 web app. Sounds like a problem with the API calls. It's giving me a Denied Access (Error 500 Interal Server Error) Can anybody help me here ?

Config :

knp_gaufrette:
    stream_wrapper: ~

    adapters:
        local_adapter:
            local:
                directory: %kernel.root_dir%/../web/uploads/img
        aws_s3_adapter:
            aws_s3:
                service_id: 'et.aws_s3'
                bucket_name: mybucket
                options:
                    create: false
                    directory: 'uploads'

    filesystems:
        aws_s3_fs:
            adapter:    aws_s3_adapter
        local_fs:
            adapter:    local_adapter

vich_uploader:
    db_driver: orm
    storage: gaufrette
    mappings:
        image:
            uri_prefix: https://s3.amazonaws.com/mybucket # you'll need this set to use the Vich URL generator
            upload_destination: aws_s3_fs
            namer: vich_uploader.namer_uniqid
            delete_on_remove: true
            delete_on_update: true
            inject_on_load:   true

Services :

services:
    et.aws_s3:
        class: Aws\S3\S3Client #Gaufrette\Adapter\AwsS3
        factory_class: Aws\S3\S3Client
        factory_method: factory
        arguments:
            -
                key: key
                secret: key
                region: us-west-2

Stack trace:

[1] Aws\S3\Exception\AccessDeniedException: Access Denied
    at n/a
        in C:\xampp2\htdocs\WebProject\vendor\aws\aws-sdk-php\src\Aws\Common\Exception\NamespaceExceptionFactory.php line 91

    at Aws\Common\Exception\NamespaceExceptionFactory->createException('Aws\S3\Exception\AccessDeniedException', object(EntityEnclosingRequest), object(Response), array('code' => 'AccessDenied', 'message' => 'Access Denied', 'type' => 'client', 'request_id' => 'B4966F7BBECF30F3', 'parsed' => object(SimpleXMLElement)))
        in C:\xampp2\htdocs\WebProject\vendor\aws\aws-sdk-php\src\Aws\Common\Exception\NamespaceExceptionFactory.php line 76

    at Aws\Common\Exception\NamespaceExceptionFactory->fromResponse(object(EntityEnclosingRequest), object(Response))
        in C:\xampp2\htdocs\WebProject\vendor\aws\aws-sdk-php\src\Aws\Common\Exception\ExceptionListener.php line 55

    at Aws\Common\Exception\ExceptionListener->onRequestError(object(Event), 'request.error', object(EventDispatcher))
        in  line 

    at call_user_func(array(object(ExceptionListener), 'onRequestError'), object(Event), 'request.error', object(EventDispatcher))
        in C:\xampp2\htdocs\WebProject\app\cache\dev\classes.php line 1790

    at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(array(object(ExceptionListener), 'onRequestError'), array('Guzzle\Http\Message\Request', 'onRequestError')), 'request.error', object(Event))
        in C:\xampp2\htdocs\WebProject\app\cache\dev\classes.php line 1723

    at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('request.error', object(Event))
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Message\Request.php line 589

    at Guzzle\Http\Message\Request->processResponse(array('handle' => object(CurlHandle)))
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Message\Request.php line 378

    at Guzzle\Http\Message\Request->setState('complete', array('handle' => object(CurlHandle)))
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Message\EntityEnclosingRequest.php line 49

    at Guzzle\Http\Message\EntityEnclosingRequest->setState('complete', array('handle' => object(CurlHandle)))
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php line 303

    at Guzzle\Http\Curl\CurlMulti->processResponse(object(EntityEnclosingRequest), object(CurlHandle), array('msg' => '1', 'result' => '0', 'handle' => 'Resource id #2420'))
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php line 257

    at Guzzle\Http\Curl\CurlMulti->processMessages()
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php line 240

    at Guzzle\Http\Curl\CurlMulti->executeHandles()
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php line 224

    at Guzzle\Http\Curl\CurlMulti->perform()
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php line 111

    at Guzzle\Http\Curl\CurlMulti->send()
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMultiProxy.php line 94

    at Guzzle\Http\Curl\CurlMultiProxy->send()
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Http\Client.php line 284

    at Guzzle\Http\Client->send(object(EntityEnclosingRequest))
        in C:\xampp2\htdocs\WebProject\vendor\aws\aws-sdk-php\src\Aws\Common\Client\AbstractClient.php line 256

    at Aws\Common\Client\AbstractClient->send(object(EntityEnclosingRequest))
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Service\Client.php line 136

    at Guzzle\Service\Client->execute(object(S3Command))
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Service\Command\AbstractCommand.php line 153

    at Guzzle\Service\Command\AbstractCommand->execute()
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Service\Command\AbstractCommand.php line 189

    at Guzzle\Service\Command\AbstractCommand->getResult()
        in C:\xampp2\htdocs\WebProject\vendor\guzzle\guzzle\src\Guzzle\Service\Client.php line 76

    at Guzzle\Service\Client->__call('CreateBucket', array(array('Bucket' => 'eventori', 'LocationConstraint' => 'us-west-2')))
        in C:\xampp2\htdocs\WebProject\vendor\aws\aws-sdk-php\src\Aws\Common\Client\AbstractClient.php line 104

    at Aws\Common\Client\AbstractClient->__call('createBucket', array(array('Bucket' => 'eventori', 'LocationConstraint' => 'us-west-2')))
        in C:\xampp2\htdocs\WebProject\vendor\knplabs\gaufrette\src\Gaufrette\Adapter\AwsS3.php line 254

    at Aws\S3\S3Client->createBucket(array('Bucket' => 'eventori', 'LocationConstraint' => 'us-west-2'))
        in C:\xampp2\htdocs\WebProject\vendor\knplabs\gaufrette\src\Gaufrette\Adapter\AwsS3.php line 254

    at Gaufrette\Adapter\AwsS3->ensureBucketExists()
        in C:\xampp2\htdocs\WebProject\vendor\knplabs\gaufrette\src\Gaufrette\Adapter\AwsS3.php line 125

    at Gaufrette\Adapter\AwsS3->write('5535ad181397d.png', '')
        in C:\xampp2\htdocs\WebProject\vendor\knplabs\gaufrette\src\Gaufrette\Filesystem.php line 122

    at Gaufrette\Filesystem->write('5535ad181397d.png', '', true)
        in C:\xampp2\htdocs\WebProject\vendor\vich\uploader-bundle\Storage\GaufretteStorage.php line 56

    at Vich\UploaderBundle\Storage\GaufretteStorage->doUpload(object(PropertyMapping), object(UploadedFile), '', '5535ad181397d.png')
        in C:\xampp2\htdocs\WebProject\vendor\vich\uploader-bundle\Storage\AbstractStorage.php line 67

    at Vich\UploaderBundle\Storage\AbstractStorage->upload(object(Image), object(PropertyMapping))
        in C:\xampp2\htdocs\WebProject\vendor\vich\uploader-bundle\Handler\UploadHandler.php line 64

    at Vich\UploaderBundle\Handler\UploadHandler->upload(object(Image), 'imageFile')
        in C:\xampp2\htdocs\WebProject\app\cache\dev\appDevDebugProjectContainer.php line 9126

    at VichUploaderBundleHandlerUploadHandler_00000000534e394600000000143551d5->upload(object(Image), 'imageFile')
        in C:\xampp2\htdocs\WebProject\vendor\vich\uploader-bundle\EventListener\Doctrine\UploadListener.php line 41

    at Vich\UploaderBundle\EventListener\Doctrine\UploadListener->prePersist(object(LifecycleEventArgs))
        in C:\xampp2\htdocs\WebProject\vendor\symfony\symfony\src\Symfony\Bridge\Doctrine\ContainerAwareEventManager.php line 63

    at Symfony\Bridge\Doctrine\ContainerAwareEventManager->dispatchEvent('prePersist', object(LifecycleEventArgs))
        in C:\xampp2\htdocs\WebProject\vendor\doctrine\orm\lib\Doctrine\ORM\Event\ListenersInvoker.php line 117

    at Doctrine\ORM\Event\ListenersInvoker->invoke(object(ClassMetadata), 'prePersist', object(Image), object(LifecycleEventArgs), '4')
        in C:\xampp2\htdocs\WebProject\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php line 896

    at Doctrine\ORM\UnitOfWork->persistNew(object(ClassMetadata), object(Image))
        in C:\xampp2\htdocs\WebProject\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php line 1683

    at Doctrine\ORM\UnitOfWork->doPersist(object(Image), array('00000000534e3b0d00000000143551d5' => object(Event), '00000000534e272c00000000143551d5' => object(User), '00000000534e3df700000000143551d5' => object(Image)))
        in C:\xampp2\htdocs\WebProject\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php line 2229

    at Doctrine\ORM\UnitOfWork->cascadePersist(object(Event), array('00000000534e3b0d00000000143551d5' => object(Event), '00000000534e272c00000000143551d5' => object(User), '00000000534e3df700000000143551d5' => object(Image)))
        in C:\xampp2\htdocs\WebProject\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php line 1702

    at Doctrine\ORM\UnitOfWork->doPersist(object(Event), array('00000000534e3b0d00000000143551d5' => object(Event), '00000000534e272c00000000143551d5' => object(User), '00000000534e3df700000000143551d5' => object(Image)))
        in C:\xampp2\htdocs\WebProject\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php line 1639

    at Doctrine\ORM\UnitOfWork->persist(object(Event))
        in C:\xampp2\htdocs\WebProject\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php line 579

    at Doctrine\ORM\EntityManager->persist(object(Event))
        in C:\xampp2\htdocs\WebProject\src\ET\CoreBundle\Controller\EventController.php line 63

    at ET\CoreBundle\Controller\EventController->createAction(object(Request))
        in  line 

    at call_user_func_array(array(object(EventController), 'createAction'), array(object(Request)))
        in C:\xampp2\htdocs\WebProject\app\bootstrap.php.cache line 3029

    at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
        in C:\xampp2\htdocs\WebProject\app\bootstrap.php.cache line 2991

    at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
        in C:\xampp2\htdocs\WebProject\app\bootstrap.php.cache line 3140

    at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
        in C:\xampp2\htdocs\WebProject\app\bootstrap.php.cache line 2384

    at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
        in C:\xampp2\htdocs\WebProject\web\app_dev.php line 28
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dousaoxiancy199896 2015-04-21 15:54
    已采纳

    Turns out my bucket region was wrong. I thought I had created it in us-west-2 but apparently it had no region set to it.

    Changed:

    region: us-west-2

    To

    region: ~

    点赞 评论

相关推荐 更多相似问题