Openstack Object Storage developer Guide/official swift API documentation-translation (2)

Source: Internet
Author: User

In the previous article, the translation introduced Part 1 of the Basic API information in the official swift documentation. This article completes the API operations of the most important storage service. Now let's get started = d

3. Storage Service API operations (API operations for storage services)

3.1. storage account services 3.1.1. obtain the container list (list containers) 3.1.2. obtain account metadata (retrieve account metadata) 3.1.3. create/update account metadata (Create/update account metadata) 3.1.4. delete account metadata 3.2. storage Container Services 3.2.1. list objects 3.2.2. create container 3.2.3. delete container 3.2.4. obtain container metadata (retrieve container metadata) 3.2.5. create/update container metadata (Create/update metainer metadata) 3.2.6. delete metainer metadata 3.3. create static website 3.3.1. static web middleware via SWIFT 3.3.2. set error pages for static sites 3.4. object Storage Service (storage object services) 3.4.1. get object (retrieve object) 3.4.2. create/update object 3.4.3. assign a CORS header (assigning CORS headers to requests) 3.4.4 to the request. enabling File compression with the content-encoding header 3.4.5. enabling browser bypass with the content-Disposition Header 3.4.6. use the X-delete-after and X-delete-at headers to make the object expire (expiring objects with the X-delete-after and X-delete-at headers) 3.4.7. object versioning 3.4.8. copy object 3.4.9. delete object 3.4.10. get object metadata (retrieve object metadata) 3.4.11. update object metadata)

This chapter describes the rest APIs that interact with the storage components in openstack object storage service. All requests are obtained successfully in the authentication phase.X-storage-URLDirectly sent to the host.

The following requirements must be met when using the storage service:

    • The container name cannot exceed 256 bytes and cannot contain the '/' character '/';
    • The object name cannot exceed 1024 bytes and cannot contain reserved characters;
    • The object and container names must be URL-encoded and UTF-encoded.

The following sections describe the actions that may be executed in the storage system. Section 3.1 describes the actions at the account level in the storage system. Section 3.2 describes the actions at the container level in the storage system; section 3.4 (incorrect in the original article) describes the object-level actions in the storage system.

 

3.1. storage account services)

The following operations are performed at the account level of the URL. For example, the URL of the following request ends with an account string stored in openstack:

Example 3.1. http request stored by account: Basic Structure

 
Method/V1/<Account>HTTP/1.1

3.1.1. Get the container list

For an accountX-storage-URLRunGet The Operation will retrieve the container list under this account and sort it by name. The order of names is determined by the binary comparison. A simple built-in sorting method is implemented using the memcmp () function of SQLite and is irrelevant to encoding. The following list describes the optional parameters supported by this request.

Query Parameters
Limit Integer N, indicating that the returned result contains only N values
Marker String X, returns the container list with a name greater than the specified string X.
End_marker String X, returns the container list with a smaller name than the specified string
Format Set the response data format to JSON or XML.

 

 

 

 

 

 

Currently, you cannot query by prefix at the account level.

Example 3.2. Request for obtaining the iner list

GET/<APIVersion>/<Account>HTTP/1.1 HOST: storage. swiftdrive. comx-auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb

The container List is included in the response body, with one container name per line. When no container is found in the query account, a response message with no content and status code 204 is returned.

Example 3.3. Obtain the container LIST Response

 
HTTP/1.1 200 okdate: Thu, 07 Jun 2010 18:57:07 gmtserver: apachecontent-type: text/plain; charset = UTF-8Content-Length: 32
 
Imagesmoviesdocumentsbackups

3.1.1.1. serialization list output

If you addFormat = xmlOrFormat = JSONParameter pair, the server serializes the iner list in the specified format and then returns the result. The following example is returned based on the corresponding format.

Example 3.4. Container details request: JSON

 
GET/<APIVersion>/<Account>? Format = json http/1.1 HOST: storage. swiftdrive. comcontent-length: 0x-storage-token: 182f9c0af0e828cfe3281767d29d19f4

Example 3.5. Container response: JSON

 
HTTP/1.1 200 okdate: Tue, 25 Nov 2008 19:39:13 gmtserver: apachecontent-type: Application/JSON; charset = UTF-8
[{"Name": "test_container_1", "Count": 2, "bytes": 78 },{ "name": "test_container_2", "Count": 1, "bytes": 17}]

Example 3.6. Container details request: XML

 
GET/<APIVersion>/<Account>? Format = xml HTTP/1.1 HOST: storage. swiftdrive. comcontent-length: 0x-storage-token: 182f9c0af0e828cfe3281767d29d19f4

Example 3.7. Container response: XML

 
HTTP/1.1 200 okdate: Tue, 25 Nov 2008 19:39:13 gmtserver: apachecontent-type: Application/XML; charset = UTF-8
 <?  XML version = "1.0" encoding = "UTF-8"  ?>  < Account  Name  = "Michaelbarton"  >      <  Container  >          <  Name  > Test_container_1 </  Name  >          <  Count  > 2</  Count  >          <  Bytes  > 78 </  Bytes  >      </  Container  >      <  Container  >          <  Name > Test_container_2 </  Name  >          <  Count  > 1 </  Count  >          <  Bytes  > 17 </  Bytes  >     </  Container  >  </  Account  > 

3.1.1.2. Control of the container large list

The openstack Object Storage System can return a maximum of 10,000 container names for each request. To obtain the sub-sequence of the iner name list, another request must useMarkerParameters. This parameter table shows where the list ends. The system will return all iner names with names greater than this marker, and a maximum of 10,000 container names can be returned. Note: When the marker value is sent through an HTTP request, it should be URL-encoded.

We can useLimitParameters.

If the length of the returned container name list is exactly the same as the limit value (or 10,000 when limit is not used), it indicates that there may be other container names that meet the condition not returned.

Example 3.8. List a long container list

For example, we use a list of container names with a length of 5.

 
Applesbananaskiwisorangespears

We will use the limit value of 2 to show how this works:

 
GET/<APIVersion>/<Account>? Limit = 2 host: storage. swiftdrive. comx-auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
 
Applesbananas

Since we receive two container names (with the same limit value), we guess there are more container names to be listed. Therefore, we use the marker parameter to create another request. The value of marker is the last one in the container list returned by the previous request:

GET/<APIVersion>/<Account>? Limit = 2& Marker= Bananashost: storage. swiftdrive. comx-auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
 
Kiwisoranges

We have received a list of containers with a length of 2. Similarly, we continue to request:

GET/<APIVersion>/<Account>? Limit = 2& Marker= Orangeshost: storage. swiftdrive. comx-auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
 
Pears

This time, we only received the container list with a length of 1, which is smaller than the requested limit value. Therefore, no more container names need to be listed, that is, they have reached the end of the list.

UseEnd_markerParameter, we can limit that the container name in the returned results is smaller than the given value.

GET/<APIVersion> <Account>? End_marker = orangeshost: storage. swiftdrive. comx-auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
 
Applesbananaskiwis

3.1.2. Get account metadata

Use on an accountHeadYou can obtain the number of iner and total storage bytes under this account. This information is returned through two custom headers:X-account-container-countAndX-account-bytes-used. Because SWIFT is designed to store massive amounts of data, you should be extremely careful when using integer-type storage accounts to use bytes. If your platform supports this, it can be converted to a 64-bit unsigned integer.

Example 3.9. Request for retrieving account metadata

Head/<APIVersion>/<Account>HTTP/1.1 HOST: storage. swiftdrive. comx-auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb

If the request is successful, a 204 (NO content) response is returned. If an invalid account or access key error is returned, a 401 (unauthorized) response is returned.

Example 3.10. Get the account metadata response

 
HTTP/1.1 204 no contentdate: Thu, 07 Jun 2010 18:57:07 gmtserver: apachex-account-container-count: 3x-account-bytes-used: 323479

3.1.3. Create/update account metadata

You can use custom metadata headers on account-level Uris.X-account-meta -*Format definition.

If you want to create or update the metadata header of an account, you must usePostQuery. The same key/value pairs that can be used in subsequent requests will overwrite the previous values.

Example 3.11. Request for updating account metadata

 
Post/<APIVersion>/<Account>HTTP/1.1 HOST: storage. clouddrive. comx-auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbbX-Account-Meta-Book: mobydickx-account-meta-Subject: whaling

This request will not have a response that contains the message body. If a 204 Status Code has no content, the update is successful.

Example 3.12. Response to account metadata update

HTTP/1.1 204 no contentcontent-length: 0content-type: text/html; charset = UTF-8Date: sat, 09 Jun 2012 19:16:29 GMT

To confirm that your metadata has been changed, you need to executeHeadRequest. Note: do not include any metadata in your head request.

Example 3.13. Request for viewing account metadata

 
Head/<APIVersion>/<Account>HTTP/1.1 HOST: storage. clouddrive. comx-auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb

Example 3.14. view the account metadata response

HTTP/1.1 204 no contentx-account-meta-book: mobydickx-account-meta-Subject: whalingx-account-object-count: 5x-timestamp: 1323466696.21566x-account-container-count: 5x-account-bytes-used: 46988accept-ranges: bytescontent-length: 0 Date: sat, 09 Jun 2012 19:16:59 GMT

3.1.4. Delete account metadata

To delete an account's metadata, we need to use that specific header information to send a null valuePostRequest, such as X-account-meta-book :.

If the tool you use to interact with Swift does not support sending requests that contain null headers values (for example, older versions of curl), you can use the header "X-Remove-Account-meta-Name: Any value, for example, X-Remove-account-meta-book: X. This value will be ignored.

Example 3.15. Request for deleting account metadata

Post/<APIVersion>/<Account>HTTP/1.1 HOST: storage. clouddrive. comx-auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbbX-Remove-Account-Meta-Book: x

No response containing the message body is returned for this request. A 204-status-code-free response indicates that the request is successfully deleted.

 

 

Now, I am tired of t ^ t. After completing this, I will merge section 3. 2. (merged). This is a section ^_^.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.