The preview of CloudIQ Storage brings Amazon S3-like functionality to Managed Service Providers, organizations, and businesses. It opens up new possibilities with distributed, reliable storage of data and and importantly, computational storage.

CloudIQ Storage exposes a RESTful interface that clients can use to store and retrieve files. Using cURL you can be on your way to PUTing and GETing files to CloudIQ Storage or any RESTful server that accepts files. This post is a follow-up to the REST-esting with cURL.

The following are basic curl commands to test PUT/GET of files

PUT a file

curl -i -u fabric-admin:fabric-admin -X PUT -T "test" http://192.168.0.165:16088/files/test

where,
i – show response headers
u – server authentication information, in the form of user:password
X – pass a HTTP method name
T – name of file to upload
The above command PUTs test file.

Optionally, you can leave out the file part in the URL, ending the URL with a trailing slash. cURL will append the local file name in this case. Note that you must use a trailing slash (/) on the last directory to tell cURL to use the file name as specified in the -T argument or cURL will use your last directory name as the remote file name to use.

curl -i -u fabric-admin:fabric-admin -X PUT -T "test" http://192.168.0.165:16088/files/

The above command transfers test file to http://192.168.0.165:16088/files/.

PUT multiple files in single command

You can PUT multiple files via a single command by enclosing them within braces as shown below:

curl -i -u fabric-admin:fabric-admin -X PUT -T "{test4,test5}" http://192.168.0.165:16088/files/

The above command transfers files test4 and test5 to http://192.168.0.165:16088/files/.

If you have many files with the almost the same name but differentiated from each other by a number (say, test4, test5, test6, test7), you could use an alternative to the above command to transfer all these files in one cURL command:

curl -i -u fabric-admin:fabric-admin -X PUT -T "test[4-6]" http://192.168.0.165:16088/files/

GET a file

curl -u fabric-admin:fabric-admin -O http://192.168.0.165:16088/files/test4

where,
O – use the remote file name for the local file
The above command GETs the contents of file test4 from remote location http://192.168.0.165:16088/files/test4 and writes the output to local file named like the remote file (in this case, test4).

If you want to store the contents in a local file with a name different from the remote file name, you could use the -o option:

curl -u fabric-admin:fabric-admin -o test10 http://192.168.0.165:16088/files/test4

The above command GETs the contents of file test4 from remote location http://192.168.0.165:16088/files/test4 and writes the output to local file test10.

Get HEADers
There are times when you just need the headers for a file. You could retrieve the headers for a file by running the following command:

curl -I -u fabric-admin:fabric-admin http://192.168.0.165:16088/files/test4

where,
I – fetches the HTTP headers only
The above command will display the HTTP headers returned by http://192.168.0.165:16088/files/test4

If you want to capture the file contents and the HTTP headers at the same time, you can use the -D option:

curl -u fabric-admin:fabric-admin -D "test4-headers" -O http://192.168.0.165:16088/files/test4

The above command GETs the contents of file test4 from remote location http://192.168.0.165:16088/files/test4 and at the same time outputs the HTTP headers to file test4-headers

For more examples using cURL for testing web services, see here.