使用 php 在桶谷歌云存储中创建文件夹

2022-01-25 00:00:00 google-cloud-storage php

我对谷歌云存储很陌生.

I am very new to the google cloud storage.

我想使用 php 编码在存储桶中创建文件夹.我搜索了很多网站,在 1 上我看到它是这样写的:

I want to create folder in bucket using php coding. I have searched a quite few sites and on 1 i saw it was written:

"在存储桶中创建文件夹将创建一个以目录命名的占位符对象,没有数据内容,mimetype 为 application/x-directory.不支持在 Google 存储管理器中创建的目录占位符对象."

"Creating a folder inside a bucket will create a placeholder object named after the directory, has no data content and the mimetype application/x-directory. Directory placeholder objects created in Google Storage Manager are ​not supported."

我不明白它想说什么.我该如何创建文件夹,请帮帮我.我尝试使用以下代码:

I could not understand what it is trying to say. How can i create folder please help me out. I tried using the following code:

$req = new Google_HttpRequest("http://commondatastorage.googleapis.com/bucket/myfoldertrial");
$req->setRequestHeaders(array(
'x-goog-project-id' => 21212,
'x-goog-acl' => 'public-read',
'Content-Type' => 'application/x-directory'
));
$req->setRequestMethod('PUT');
$req->setPostBody('myfoldertrial');

我正在使用以下链接中的 API:

I am using the API from following link:

Google API for PHP

请帮助我使用 PHP 创建文件夹.

Please help me out creating folder using PHP.

推荐答案

您可能实际上不需要创建文件夹.

You probably don't actually need to create a folder.

Google Storage 不像您的操作系统的文件系统使用的树形结构,所有对象都存储在顶层的存储桶中.但是,您可以为对象命名,其中包含斜线,因此它看起来像是在文件夹中 - Users/username/docs/2012/09/21/activity.csv 是对象的完美名称,不需要任何支持文件夹.

Google Storage isn't a tree structure like your operating system's filesystem uses, all Objects are stored in buckets at the top level. However you can give an Object a name with slashes in it, so it will kind of look like it is in a folder - Users/username/docs/2012/09/21/activity.csv is a perfectly good name for an Object and doesn't need any supporting folders.

一旦你有了这种方案的对象,你就可以列出它们,就像你正在查看带有 delimiterprefix 的文件夹的内容一样这些文档的参数.

Once you've got Objects with this sort of scheme in place, you can list them as if you were viewing the contents of a folder with the delimiter and prefix parameters as per these docs.

所以如果你只想创建 myfoldertrial 这样你就可以上传 example.png 进去,不需要创建文件夹,你可以直接上传到 <代码>myfoldertrial/example.png.

So if you only wanted to create myfoldertrial so you could upload example.png into it, there's no need to create the folder, you can just upload straight to myfoldertrial/example.png.

相关文章