Ask Your Question

How to upload a file in Swift Storage system using python?

asked 2016-05-25 18:25:20 -0500

Ghada gravatar image

I want to upload some files in Swift, having each around 1 giga bytes as sizes. I executed this code in python (for one file to upload):

import swiftclient
swift = swiftclient.client.Connection(auth_version='1',user='test:tester',key='testing',authurl='http://localhost:8080/auth/v1.0')
# Create the swift container
# Upload the object
with open('file.jpg', 'rb') as f:
    file_data =
swift.put_object('container', 'file.jpg', file_data)

# List the containers
print swift.head_account()

I got this error : Object PUT failed 503 Service Unavailable swift. What can be the reason of the error ?

Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2016-05-26 16:18:11 -0500

Bart gravatar image

Hi, In your code

with open('file.jpg', 'rb') as f: file_data = swift.put_object('container', 'file.jpg', file_data)

it seems to me that you try to read the full 1GB at once. Code that works for me is: print "uploading file ..." oFileToUpload = open("file.jpg", "rb") swiftclient.client.put_object(self.auth[0], self.auth[1], "container", "file.jpg", oFileToUpload) oFileToUpload.close()

so, essentially, just openinng the file and passing the file object itself to the swift API call without reading anything myself - swift does that for you. Kind regards, Bart

edit flag offensive delete link more


Thank you for your response.

What is self.auth ?

How did you define it ?

Ghada gravatar imageGhada ( 2016-05-27 14:34:04 -0500 )edit

Hi, self.auth = swiftclient.client.get_auth_keystone(auth_info['auth_url'], auth_info['username'], auth_info['password'], os_options)


os_options = { 'tenant_name' : 'admin' } and auth_info a dict with entries for the keys

Bart gravatar imageBart ( 2016-05-30 17:16:05 -0500 )edit

Actually, I allocated to Swift only 1 GB of storage capacity while the installation by using this command : sudo truncate -s 1GB /srv/swift-disk.

So, the storage space is almost full. How can I increase the space allocated to Swift ??

Ghada gravatar imageGhada ( 2016-05-30 18:09:59 -0500 )edit

Your Answer


Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2016-05-25 18:02:23 -0500

Seen: 1,005 times

Last updated: May 26 '16