Archive for the ‘swift’ Category

Set Metadata with Object in Object Storage


Set Metadata:

curl -X POST -H “X-Auth-Token:$TOKEN” -H “X-Object-Meta-jsonpolicy:{policy value}” $STORAGE_URL/bar/foobar.txt

Retrive Metadata:

For some reasons, I cannot retrieve metadata with curl command. So, lets use swift command:

swift bar foobar.txt

Setting meta data with Swift Object



Value of a custom meta data does not take a new line. Value breaks at new line.

Categories: openstack, swift Tags:

Change Default Response of Swift GET Request

Swift is the object storage of OpenStack. Python-SwiftClient is the default client program to interact with OpenStack Swift Storage. In this note along with python-swiftclient I would also use ‘curl’ command occasionally. 

The objective of this note, is to change / modify the content of the received file with  swift GET request. To illustrate, lets assume I have a file (foo.txt) in a container named ‘bar’ inside swift storage.  ‘foo.txt’ contain following following line “You are who you are!”. So, if we send a GET request for ‘foo.txt’ we would get the original content “You are who you are”. But here, I would illustrate, how you can change swift-objectserver so that instead of the original content you would receive ‘yes, you are smart’. Why you need this – I won’t tell you. Find your own use case.

So, this is what happens:

Swift Default behavior

What we want to achive:

Desired output

How we do it:

In my environment, I have following token and Storage url set up. So that my curl command connect to the right endpoint with valid token.

Token and Storage URL

Now, I would point out changes required:

Now, let me explain how I can do this change.

Swift Object server is responsible to read requested file from disk and pass the file content back to the swift proxy server.

The actual reading of the requested file, is done in this   line (see github) or shown here below:

response = Response(
request=request, conditional_response=True)

In this case, the Response Class, build the response for the given request. ‘app_iter’ has the iterator of the disk file as shown in the file. 

But Instead of ‘app_iter’, we can also give the actual ‘body’ of the request. See, the definition of  Request Class for more information. 

If you look into the following figure, we are commenting out ‘app_iter’ and giving ‘body’ with our desired value. 

Changes in the Swift code 

The next thing what we need, is to set the content length which is set by the ‘obj_size’ variable. Which I am setting next with len(response.body).

Boom! Now, restart you object server. And  send the request for the file.

Categories: openstack, swift Tags: ,

Uploading & downloading file from Swift using curl command

upload a file:
curl -i $STORAGE_URL/container1/json/config -X PUT -H “X-Auth-Token:$TOKEN” -T

> the file to be created in named ‘json/config’. ‘/’ is totally valid in swift.
-T option is used to pass the data. In this case, file /json/config’ would have the data contained in in local filesystem.

> You have to know STORAGE_URL & TOKEN for your swift server.
for me,
and $TOKEN = 226e5e68940743168cbbdfa9a346bd87

download a file:
curl -i $STORAGE_URL/container1/json/config -X GET -H “X-Auth-Token:$TOKEN”


the file name to download is ‘/json/config’. Don’t be confuse with ‘/’ in the filename. In swift you can put ‘/’ inside filename. But filename can also be as simple as ‘config’

Categories: openstack, swift