0

I am using swift object store on Bluemix to save some of my multimedia images. I noticed that SWIFT CLI tool has an option --prefix to upload a directory to the object store. I understand that Object store does not have its directory structure but it keeps the hierarchy by prefixing the folder structure with the file name. CLI allow to download the folder using --prefix option and it create the required directory structure upon download.

I am looking for the similar functionality achieved by using the REST API. In the API documentation I dont see any way of providing the information regarding folder. Do anyone know how to achieve the same behavior using API ?

Thanks Manoj

Brian Cline
  • 20,012
  • 6
  • 26
  • 25
Manoj K Sardana
  • 153
  • 1
  • 4
  • 14

2 Answers2

1

Assuming your Object Storage container is accessible at https://host/AUTH_projectId/mycontainer, you can PUT a file at https://host/v1/AUTH_projectId/mycontainer/afolder/asubfolder/myfile.txt to create the hierarchy you are looking for:

curl -i https://host/v1/AUTH_projectId/mycontainer/afolder/asubfolder/myfile.txt -X PUT -H "Content-Length: 15" -H "Content-Type: " -H "X-Auth-Token: yourtoken"

Refer to this Openstack API: http://developer.openstack.org/api-ref-objectstorage-v1.html#createOrReplaceObject

Obviously if during download you want to recreate the folder hierarchy locally, that's up to you to do.

Frederic Lavigne
  • 704
  • 3
  • 12
0

The API itself by design can't support an upload by directory, because the API is purely a contract of how to talk to the service; by itself, it does not have visibility into your local directory structure. Individual tools will, so it's actually possible to supply a directory name to the same Swift CLI tool:

swift upload mycontainer mylocaldir

An alternative API-side solution is the Bulk Upload API within Swift's API. We enable this in both the SoftLayer and Bluemix Object Storage services. If you are able to upload a tar/tar.gz/tar.bz2 archive of your files to the API, you can instruct the API to auto-extract that into your account or container once the upload is complete.

Here is an example of how to use this API:

curl -i -X PUT -T stuff.tar.gz https://example.com/v1/AUTH_abc/container?extract-archive=tar.gz -H X-Auth-Token:mytoken

In order to include a prefix on objects that are extracted from files in your archive, you can extend the container bit above to include container/my/prefix. For instance:

https://example.com/v1/AUTH_account/container/my/prefix?extract-archive=tar.gz

If you wish for the archive to be extracted such that the top-level folders in the archive become containers, you would omit the container segment altogether. This will discard any top-level files in the archive, so make sure to all files are in folders when you create the archive. But you would end up with a URL something like this:

https://example.com/v1/AUTH_account/?extract-archive=tar.gz

Note that the archive formats supported are tar, tar.gz, and tar.bz2.

More details are available in the OpenStack Swift documentation: http://docs.openstack.org/developer/swift/middleware.html#extract-archive

Brian Cline
  • 20,012
  • 6
  • 26
  • 25