2

早上好,如何將文件上傳到谷歌雲存儲用symfony/gauferette/VichUploaderBundle

我通過VichUploaderBundle上傳我的文件本地。每件事情都很完美。

現在我不想再在本地存儲我的文件了:我想將它們存儲在Google雲端存儲。我發現KnpGaufretteBundle可用於在雲中存儲文件。

那麼,有沒有任何例子或者例如關於如何配置鏈接Gaufrette(php軟件包)KnpGaufretteBundle(symfony的束)存儲/上載/閱讀google-cloud-storage文件?

我唯一發現的是link這是GoogleCloudStorage的適配器類。

我發現有關此問題的另一個鏈接,但它提出了一個例子,用於存儲amazon-s3文件:upload-files-to-amazon-s3-with-symfony2-and-gaufrette

感謝您幫助...

回答

2

可以使用KnpGaufretteBundle做到這一點。您只需創建一個工廠,即可創建完全通過身份驗證的Google客戶端,並將Google服務存儲與該客戶​​端一起返回。類似的東西:

/** 
* @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); 
} 

您還需要配置KnpGaufretteBundle,這一下: KnpGaufretteBundle-GoogleCloudStorage

這裏有一個在GitHub上一個帖子裏介紹了工廠的問題: post

+0

GitHub上,這是我映射。謝謝你的幫助 –

相關問題