使用php在存储桶Google云存储中创建文件夹 [英] Creating folder in bucket google cloud storage using php

查看:92
本文介绍了使用php在存储桶Google云存储中创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Google云存储非常陌生.

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 Storage Manager中创建的目录占位符对象.

"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:

适用于PHP的Google API

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

Please help me out creating folder using PHP.

推荐答案

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

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

Google存储空间不是操作系统所使用的文件系统那样的树形结构,所有对象都存储在顶层的存储桶中.但是,您可以给对象起一个带斜线的名称,因此看起来就像在文件夹中一样-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.

一旦有了采用这种方案的对象,就可以像按照

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.

这篇关于使用php在存储桶Google云存储中创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆