当前位置: 首页 > 文档资料 > Ceph 中文文档 >

bucket 操作

优质
小牛编辑
127浏览
2023-12-01

PUT Bucket

创建一个新的 bucket。要创建一个 bucket,你必须有一个用户 ID 和一个有效的 AWS 访问密钥 ID 来进行身份验证请求。匿名用户不能创建 bucket。

Note

当前版本我们不支持通过 PUT /{bucket} 来请求实例。

约束条件

一般而言,bucket 名称应该遵循下述域名命名约束条件

  • Bucket 名必须是唯一的
  • Bucket 名必须以小写字母开始和结尾
  • Bucket 名可以包含破折号 (-).

语法

PUT /{bucket} HTTP/1.1
Host: cname.domain.com
x-amz-acl: public-read-write

Authorization: AWS {access-key}:{hash-of-header-and-secret}

参数

NameDescriptionValid ValuesRequired
x-amz-aclCanned ACLs.private, public-read, public-read-write, authenticated-readNo

HTTP 响应

如果 bucket 的名称是独一无二的,满足约束条件并且没有被使用,操作就会成功的。 如果已经存在同名的 bucket,并且 bucket 的所有者就是当前请求用户,操作也会返回成功的。 如果 bucket 名称已经被使用,操作将会返回失败。

HTTP StatusStatus CodeDescription
409BucketAlreadyExistsBucket already exists under different user’s ownership.

删除 Bucket

删除一个 bucket,得到成功删除 bucket 的返回信息后就可以重用该 bucket 名。

语法

DELETE /{bucket} HTTP/1.1
Host: cname.domain.com

Authorization: AWS {access-key}:{hash-of-header-and-secret}

HTTP 响应

HTTP StatusStatus CodeDescription
204No ContentBucket removed.

获取 Bucket

返回 bucket 中的对象列表

语法

GET /{bucket}?max-keys=25 HTTP/1.1
Host: cname.domain.com

参数

NameTypeDescription
prefixStringOnly returns objects that contain the specified prefix.
delimiterStringThe delimiter between the prefix and the rest of the object name.
markerStringA beginning index for the list of objects returned.
max-keysIntegerThe maximum number of keys to return. Default is 1000.

HTTP 响应

HTTP StatusStatus CodeDescription
200OKBuckets retrieved

Bucket 响应实例

GET /{bucket} 返回一个容器,包含 bucket 的下列字段

NameTypeDescription
ListBucketResultEntityThe container for the list of objects.
NameStringThe name of the bucket whose contents will be returned.
PrefixStringA prefix for the object keys.
MarkerStringA beginning index for the list of objects returned.
MaxKeysIntegerThe maximum number of keys returned.
DelimiterStringIf set, objects with the same prefix will appear in the CommonPrefixes list.
IsTruncatedBooleanIf true, only a subset of the bucket’s contents were returned.
CommonPrefixesContainerIf multiple objects contain the same prefix, they will appear in this list.

对象响应实例

ListBucketResult 包含很多对象,每个对象都包含一个 Contents 容器.

NameTypeDescription
ContentsObjectA container for the object.
KeyStringThe object’s key.
LastModifiedDateThe object’s last-modified date/time.
ETagStringAn MD-5 hash of the object. (entity tag)
SizeIntegerThe object’s size.
StorageClassStringShould always return STANDARD.

获取 Bucket 位置

获取 bucket 的 region。只有 bucket 的所有者才能发起这个请求。一个 bucket 可以在发起 PUT 请求的时候通过指定 LocationConstraint 参数来限制它的 region。

语法

如下所示在 bucket 资源后面添加 location 子资源

GET /{bucket}?location HTTP/1.1
Host: cname.domain.com

Authorization: AWS {access-key}:{hash-of-header-and-secret}

响应实例

NameTypeDescription
LocationConstraintStringThe region where bucket resides, empty string for defult region

获取 Bucket ACL

获取 bucket 的访问控制列表。请求用户需要是该 bucket 的所有者或者已经针对这个 bucket 授权了 READ_ACP 权限的用户.

语法

如下所示,在 bucket 请求后面添加 acl 子资源.

GET /{bucket}?acl HTTP/1.1
Host: cname.domain.com

Authorization: AWS {access-key}:{hash-of-header-and-secret}

响应实例

NameTypeDescription
AccessControlPolicyContainerA container for the response.
AccessControlListContainerA container for the ACL information.
OwnerContainerA container for the bucket owner’s ID and DisplayName.
IDStringThe bucket owner’s ID.
DisplayNameStringThe bucket owner’s display name.
GrantContainerA container for Grantee and Permission.
GranteeContainerA container for the DisplayName and ID of the user receiving a grant of permission.
PermissionStringThe permission given to the Grantee bucket.

设置 Bucket ACL

为一个已经存在的 bucket 设置一个访问控制。请求用户需要是该 bucket 的所有者或者已经针对 这个 bucket 授权了 WRITE_ACP 权限的用户.

语法

如下所示,在 bucket 请求后面添加 acl 子资源.

PUT /{bucket}?acl HTTP/1.1

响应实例

NameTypeDescription
AccessControlPolicyContainerA container for the request.
AccessControlListContainerA container for the ACL information.
OwnerContainerA container for the bucket owner’s ID and DisplayName.
IDStringThe bucket owner’s ID.
DisplayNameStringThe bucket owner’s display name.
GrantContainerA container for Grantee and Permission.
GranteeContainerA container for the DisplayName and ID of the user receiving a grant of permission.
PermissionStringThe permission given to the Grantee bucket.

列出 Bucket 的分块上传

GET /?uploads 返回当前正在进行中的分块上传的列表。比如:应用 程序启动了一个分块上传,但是服务尚未完成所有块的上传。

语法

GET /{bucket}?uploads HTTP/1.1

参数

你可以为 GET /{bucket}?uploads 指定一些参数,但下面这些参数都不是必须的.

NameTypeDescription
prefixStringReturns in-progress uploads whose keys contains the specified prefix.
delimiterStringThe delimiter between the prefix and the rest of the object name.
key-markerStringThe beginning marker for the list of uploads.
max-keysIntegerThe maximum number of in-progress uploads. The default is 1000.
max-uploadsIntegerThe maximum number of multipart uploads. The range from 1-1000. The default is 1000.
upload-id-markerStringIgnored if key-marker isn’t specified. Specifies the ID of first upload to list in lexicographical order at or following the ID.

响应实例

NameTypeDescription
ListMultipartUploadsResultContainerA container for the results.
ListMultipartUploadsResult.PrefixStringThe prefix specified by the prefix request parameter (if any).
BucketStringThe bucket that will receive the bucket contents.
KeyMarkerStringThe key marker specified by the key-marker request parameter (if any).
UploadIdMarkerStringThe marker specified by the upload-id-marker request parameter (if any).
NextKeyMarkerStringThe key marker to use in a subsequent request if IsTruncated is true.
NextUploadIdMarkerStringThe upload ID marker to use in a subsequent request if IsTruncated is true.
MaxUploadsIntegerThe max uploads specified by the max-uploads request parameter.
DelimiterStringIf set, objects with the same prefix will appear in the CommonPrefixes list.
IsTruncatedBooleanIf true, only a subset of the bucket’s upload contents were returned.
UploadContainerA container for Key, UploadId, InitiatorOwner, StorageClass, and Initiated elements.
KeyStringThe key of the object once the multipart upload is complete.
UploadIdStringThe ID that identifies the multipart upload.
InitiatorContainerContains the ID and DisplayName of the user who initiated the upload.
DisplayNameStringThe initiator’s display name.
IDStringThe initiator’s ID.
OwnerContainerA container for the ID and DisplayName of the user who owns the uploaded object.
StorageClassStringThe method used to store the resulting object. STANDARD or REDUCED_REDUNDANCY
InitiatedDateThe date and time the user initiated the upload.
CommonPrefixesContainerIf multiple objects contain the same prefix, they will appear in this list.
CommonPrefixes.PrefixStringThe substring of the key after the prefix as defined by the prefix request parameter.

启用/禁用 BUCKET 版本

PUT /?versioning 这个子资源用于设置已有 bucket 的版本化状态。只有 bucket 所有者才能设置这个版本状态。

版本状态可以设置为如下取值之一:

  • Enabled : 为 bucket 内的对象启用版本,放入 bucket 内的对象都会收到一个唯一的版本 ID 。
  • Suspended : 为 bucket 内的对象禁用版本,放入 bucket 内的对象其版本 ID 都是 null 。

如果从没给某一个 bucket 设置过版本状态,那它就没有版本状态;获取版本的 GET 请求就不会返回版本的状态值。

语法

PUT  /{bucket}?versioning  HTTP/1.1

请求实体

NameTypeDescription
VersioningConfigurationContainerA container for the request.
StatusStringSets the versioning state of the bucket. Valid Values: Suspended/Enabled