[英]Google Cloud Storage - Invalid bucket name (PHP)
I tried to upload a file on root in my Google cloud Storage by doing this: 我尝试通过执行以下操作在Google云端存储的根目录上载文件:
$bucketName = "bucket-name.appspot.com";
$objectName = $client_id . '_' . rand(0, 200) . '_' . $type . '.pdf';
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($datas, [
'name' => $objectName
]);
This worked and i successfully upload a file($datas)
. 这有效,我成功上传了一个
file($datas)
。
Now i created a folder in my root storage and called it "contracts"
. 现在,我在根存储中创建了一个文件夹,并将其称为
"contracts"
。 So my $bucketName
is updated to include the folder like this: 因此,我的
$bucketName
已更新为包括以下文件夹:
$bucketName = "bucket-name.appspot.com/contracts";
$objectName = $client_id . '_' . rand(0, 200) . '_' . $type . '.pdf';
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($datas, [
'name' => $objectName
]);
As you can see this is now updated to: $bucketName = "bucket-name.appspot.com/contracts";
如您所见,现在已更新为:
$bucketName = "bucket-name.appspot.com/contracts";
. 。 But this gives me this error now:
但这现在给我这个错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid bucket name: 'bucket-name.appspot.com/contracts'"
}
],
"code": 400,
"message": "Invalid bucket name: 'bucket-name.appspot.com/contracts'"
}
}
Why is that? 这是为什么?
See: 看到:
You should add /contracts/
to $objectName
. 您应该将
/contracts/
添加到$objectName
。
$bucketName = "bucket-name.appspot.com";
$objectName = '/contracts/' . $client_id . '_' . rand(0, 200) . '_' . $type . '.pdf';
$storage = new StorageClient();
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($datas, [
'name' => $objectName
]);
Withing Google Cloud Storage, there are only buckets
and objects
. 使用Google Cloud Storage时,只有
buckets
和objects
。 The notion of folders is only an illusion . 文件夹的概念只是一种幻想 。 For example, a file that you wish to access as
gs://yourbucket/yourfolder/yourfile
is bucket yourbucket
and file (object) yourfolder/yourfile
. 例如,您希望以
gs://yourbucket/yourfolder/yourfile
yourbucket
文件是bucket yourbucket
和文件(对象) yourfolder/yourfile
。
There is a dedicated article on this story at How Subdirectories work . 关于子目录的工作原理,有一篇专门的文章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.