how to upload files to Google Cloud Storage with symfony / gauferette / VichUploaderBundle

霸气de小男生 提交于 2019-12-05 07:54:06

问题


Good morning,

I am uploading my files locally through VichUploaderBundle. Every thing works perfectly.

Now I want no more store my files locally: I want to store them on Google Cloud Storage. I found that KnpGaufretteBundle could be used for storing files in the cloud.

So, is there any example or a example's link on how to configure Gaufrette (the php package) or KnpGaufretteBundle (the symfony bundle) for storing/uploading/reading files on google-cloud-storage?

The only thing I found is that link which is an adapter class for GoogleCloudStorage.

I found another link regarding this issue but it proposes an example for storing files on amazon-s3: upload-files-to-amazon-s3-with-symfony2-and-gaufrette

Thanks for you help...


回答1:


Is possible to use KnpGaufretteBundle to do that. You only need to create a factory that creates a Google Client fully authenticated and return the Google Service Storage with that Client. Something like that:

/**
 * @return \Google_Service_Storage
 */
public function createService($privateKeyPath, $password, $googleAccountName)
{
    $client = new \Google_Client();
    $scopes = array(
        'https://www.googleapis.com/auth/devstorage.read_write'
    );

    $privateKey = file_get_contents($privateKeyPath);

    $credential = new \Google_Auth_AssertionCredentials(
        $googleAccountName, $scopes, $privateKey, $password
    );

    $client->setAssertionCredentials($credential);

    return new \Google_Service_Storage($client);
}

You also need to configure the KnpGaufretteBundle, for this look at: KnpGaufretteBundle-GoogleCloudStorage

Here there's a post in GitHub where explains the factory issue: post



来源:https://stackoverflow.com/questions/33591580/how-to-upload-files-to-google-cloud-storage-with-symfony-gauferette-vichuplo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!