如何使用Google_Client库将文件上传到Google云端存储中的目录

时间:2018-05-10 17:11:35

标签: php google-cloud-storage

我想使用this answer上的Google客户端php库将文件上传到Google云存储。能够将文件上传到云存储但无法上传到云存储中的目录。我收到错误消息No such object: bucketName/abc/test.jpg

$client = new Google_Client();
putenv('GOOGLE_APPLICATION_CREDENTIALS=files/google_cloud.json');
$client->useApplicationDefaultCredentials();
$storage = new Google\Cloud\Storage\StorageClient([
    'projectId' => $googleprojectID
]);

$sPath = "files/com/test.jpg";
$objectName = "/abc/test.jpg";

$bucketName = $googlebucketName;
$bucket = $storage->bucket($bucketName);
$bucket->upload( fopen($sPath, 'r') );
$object = $bucket->object($objectName);
$info = $object->update(['acl' => []], ['predefinedAcl' => 'PUBLICREAD']);

0 个答案:

没有答案