我目前正嘗試將雲存儲文件重命名和/或移動到其他名稱/位置,但我無法使其工作。我使用https://github.com/google/google-api-php-client作爲客戶端,在上傳工作正常:如何重命名或移動Google雲端存儲中的文件(PHP API)
...
$storageService = new \Google_Service_Storage($client)
$file = new \Google_Service_Storage_StorageObject()
$file->setName('test.txt');
$storageService->objects->insert(
$bucketName,
$file,
array(
'name' => $filename,
'data' => file_get_contents($somefile)
)
);
...
所以我試圖用$ storageObject->對象 - > update()方法來更改文件名,但我不能找到這個任何文件。我使用$ storageService-> objects-> get($ bucketName,$ fileName)來獲取我想重命名的特定文件(使用$ file-> setName()),但似乎我只是無法將文件傳遞給對象 - >更新功能。我做錯了嗎?
請檢查鏈接: - https://cloud.google.com/storage/docs/gsutil/commands/mv – 2015-03-25 08:37:48
感謝您的快速答覆。我需要python作爲gsutil工具,但不幸的是它沒有安裝在服務器上。所以用google api php客戶端重命名文件是不可能的?這對我來說似乎有點奇怪,因爲可以使用php客戶端將文件上傳到存儲。 – dominikweber 2015-03-25 08:46:01
您是否在Google App Engine上運行您的應用?如果是這樣,您應該可以使用rename()直接重命名對象:https://cloud.google.com/appengine/docs/php/googlestorage/advanced#php_filesystem_functions_support_on_google_cloud_storage – Mars 2015-03-30 17:04:06