2014-08-31 34 views
1

無法將文件從GCE(Compute Engine)上傳到PHP中的GCS我嘗試使用PHP中的gsutil將文件從GCE(Google Compute Engine)上傳到GCS(Google Cloud Storage)。使用gsutil

 **exec("gsutil -m cp xxx.jpg gs://a56/upload", $output, $return_var);** 

我可以上傳使用命令文件(#gsutil -m CP XXX.JPG GS:// A56 /上傳), 但它不能在PHP工作。

apache錯誤日誌顯示權限問題。

 **OSError: [Errno 13] Permission denied: '/var/www/.config'** 

我試圖通過「搭配chmod 777的/ var/www」的避免這個問題,並添加用戶「WWW的數據」到「根」組,但我仍然有權限的問題。

 **AccessDeniedException: 403 Insufficient Permission 
    **CommandException: 1 files/objects could not be transferred. 

我該如何解決這個問題? 還是有更好的方法來上傳文件?

回答

1

我自己弄明白了。 由於權限問題,我選擇不使用gsutil上傳文件。 相反,我使用Google API客戶端庫(PHP)作爲服務帳戶。 但是,它沒有現有的例子。我在GitHub上發佈我的結果。

https://github.com/Brandon-Lin/google-cloud-storage/blob/master/upload_file_using_service_account.php

確保應用服務帳戶。
然後將P12密鑰下載到本地計算機。
然後,您應該將「客戶端ID」和「電子郵件地址」應用於我在GitHub中的示例。