Wednesday 11 May 2016

IBM Bluemix : Enhancing Cloud Applications using Managed Services - Part 5

e. Understand how to store and retrieve files using the IBM Object Storage service in Bluemix

1. Creation of a container in object storage service
Note that IBM Bluemix PaaS offers two types of Object Storage services.

Object Storage version 1 is based on SoftLayer object storage and provides a service that can be bound to a Bluemix application and is also used in some boilerplates.

Object Storage version 2 provides a flexible model to use Object Storage on IBM on-premise clouds or IBM public cloud. This section focuses on usage specific to Object Storage version 1

Before using any API services of Object Storage version 1, an authentication token must be obtained by calling the api_uri endpoint using Basic Authentication using credentials provided in VCAP_SERVICES to the application. Once obtained, containers and objects can be managed through REST API calls to the storage url returned with the token. For example, a successful authentication will have a response of the form:

HTTP/1.1 200 OK
X-Backside-Transport: OK OK
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json:charset=utf-8
Date: Fri, 30 Jan 2015 18:33:12 GMT
Set-Cookie: connect.sid=s%3AnPo52qjvdynxlvCGEAmJfs7d.HuYPqYVmtQqeImm73iUnubk2r9T0S5WIQVOL5edX08U; Path=/; HttpOnly --> X-Auth-Token: AUTH_tk924cd97c2af7475c8e6cb25d2adaccf8
X-Cf-Requestid: 969d6f00-8b85-471e-5ab5-80c36031f9fb
X-Powered-By: Express --> X-Storage-Url: https://dal05.objectstorage.softlayer.net/v1/AUTH_0c6bf5d5-b5e4-43aa-93f1-ea7065837fb8
X-Client-IP: 129.42.208.182
X-Global-Transaction-ID: 770597619

To create a container in Object Storage, use a PUT request to the storage url and append the new container name in the request. Using the example above:

curl -i -H "X-Auth-Token: AUTH_tk924cd97c2af7475c8e6cb25d2adaccf8" -X PUT https://dal05.objectstorage.softlayer.net/v1/AUTH_0c6bf5d5-b5e4-43aa-93f1-ea7065837fb8/myNewContainer

2. Perform create, upload, and list operations on an object using containers
Once the container is created, objects are manipulated by http requests. To create a file or upload with new data to an existing file, use the PUT command specifying the container in the path (simplified command omitting –H option shown):

 curl -X PUT [...] storageurl/container1 -T object.jpg
To list all of the objects in a container, use the GET command specifying the container name (simplified command shown):

 curl –X GET [...] storageurl/container1
To download an object, use the GET command specifying the object name (simplified command shown):

 curl -X PUT [...] storageurl/container1/object.jpg

3. Purpose of metadata to store information about files in object storage
For objects that are stored in object storage, information about the object is available through metadata. Object metadata includes some standard types like: last modified, length, md5 checksum, expiration date, and also supports custom data through the X-Object-Meta-{name} element. Reading metadata from an object is done using the HEAD request:

 curl –X HEAD [...] storageurl/container1
Object metadata is created or updated with the http POST command. Selected standard metadata are modifiable and X-Object-Meta-{name} items may be created as needed.
References:

https://www.ng.bluemix.net/docs/#services/ObjectStorage/index.html#ObjectStorage
http://developer.openstack.org/api-ref-objectstorage-v1.html

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.

Recent Comments

Contact Form

Name

Email *

Message *

Followers