Skip to content

Instantly share code, notes, and snippets.

@drewkerrigan
Created June 5, 2012 16:51
Show Gist options
  • Save drewkerrigan/2876196 to your computer and use it in GitHub Desktop.
Save drewkerrigan/2876196 to your computer and use it in GitHub Desktop.
Swift Usage Examples
Execute the following command and make a note of X-Auth-Token. You will need this token to use in all subsequent commands.
curl -v -H 'X-Storage-User: system:root' -H 'X-Storage-Pass: testpass' http://10.80.83.68:8077/auth/v1.0
In the following command examples we are using 'AUTH_tk65840af9f6f74d1aaefac978cb8f0899' as the X-Auth-Token. Replace this with the appropriate token you obtained in the above step.
To create a container:
curl -X PUT -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer
To list all containers in current account:
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/
Uploading a file "file1" to container "mycontainer"
curl -X PUT -T file1 -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/
To list all objects in a container:
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer
To list all objects in a container that starts with a particular prefix "fi":
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/?prefix=fi
To download a particular file "file1" from the container "mycontainer":
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/file1
To download file1 and save it locally as localfile1:
curl -o localfile1 -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/file1
To delete a container "mycontainer"
curl -X DELETE -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer
To delete a specific file "file1" from the container:
curl -X DELETE -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/file1
To get metadata associated with a Swift account:
curl -v -X HEAD -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/
To get metadata associated with a container:
curl -v -X HEAD -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer
You can request the data from Swift in XML or JSON format by specifying the "format" paramater. This parameter can be applied to any of the above requests. Here are a few examples:
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/?format=json
curl -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/?format=xml
The above operations can also be done using 'swift' command. For instructions on using 'swift' command, please refer to "swift --help".
@laskfla
Copy link

laskfla commented Apr 25, 2017

--to list file metadata (file size, last modifiled time, etc) , use the -I option, -X HEAD wont work
curl -I -H 'X-Auth-Token: AUTH_tk65840af9f6f74d1aaefac978cb8f0899' http://10.80.83.68:8077/v1/AUTH_system/mycontainer/file1

@archupsg03
Copy link

Is there curl command to do bulk delete ?

@go4875
Copy link

go4875 commented Feb 21, 2018

Hi all
does anyone know if curl will work with or using tempurl?
Also, with the URL above, is that with SWIFT auth or KEYSTONE auth? Thanks
One more thing, has anyone gotten SWIFT to work with a NGINX in front? our SWIFT is behind firewall, so I am trying to configure a reverse proxy to pass everything. if anyone can share their experience. would be appreciated. Thanks all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment