3.9. Creating Objects

Enough with containers already, let's start to upload some objects. Suppose you had a local directory full of dog pictures:

 

Example 3.17. Sample File Listing

				
$ ls -l
total 504
-rw-r--r--@ 1 petecj2  staff   44765 Nov  7 14:49 JingleRocky.jpg
-rw-r--r--@ 1 petecj2  staff  100864 Nov  7 14:47 RockyAndBuster.jpg
-rw-r--r--@ 1 petecj2  staff  107103 Nov  7 14:47 SittingBuster.jpg

		

In order to put one of them in a container called "dogs" with cURL, you'd do this:

 

Example 3.18. Creating and Uploading an Object to a Container

curl –X PUT -i \
    -H "X-Auth-Token: fc81aaa6-98a1-9ab0-94ba-aba9a89aa9ae" \
    -T JingleRocky.jpg" \
    https://storage.swiftdrive.com/v1/CF_xer7_343/dogs/JingleRocky.jpg
            
				
HTTP/1.1 201 Created
Content-Length: 118
Content-Type: text/html; charset=UTF-8
Etag: f7d40eceffdd9c2ecab226105737b2a6
Last-Modified: Mon, 07 Nov 2011 22:51:29 GMT
X-Trans-Id: txd131cc897c78403daf5fad010d4d7152
Date: Mon, 07 Nov 2011 22:51:30 GMT

<html>
 <head>
  <title>201 Created</title>
 </head>
 <body>
  <h1>201 Created</h1>
  <br /><br />



 </body>
</html>

			

The object gets named from whatever we append to the URL path beyond the container name and the -T switch lets us name a file to push with the operation as the request body. We can confirm the upload by checking the container again:

 

Example 3.19. cURL List Container Showing Newly Uploaded Object

curl –X GET -i \
    -H "X-Auth-Token: fc81aaa6-98a1-9ab0-94ba-aba9a89aa9ae" \
    https://storage.swiftdrive.com/v1/CF_xer7_343/dogs
            
				
HTTP/1.1 200 OK
X-Container-Object-Count: 1
X-Container-Read: .r:*,.rlistings
X-Container-Bytes-Used: 44765
Accept-Ranges: bytes
Content-Length: 16
Content-Type: text/plain; charset=utf-8
X-Trans-Id: tx83be89d4e1a34eacbfeebcdfc7a7f2e7
Date: Mon, 07 Nov 2011 22:56:25 GMT

JingleRocky.jpg

			

Notice that the container metadata now reflects the number of objects and the bytes match what we saw when we did the directory listing. After uploading the other two similarly, we get a full object listing:

 

Example 3.20. cURL List Container Showing Multiple Newly Uploaded Objects

curl –X GET -i \
    -H "X-Auth-Token: fc81aaa6-98a1-9ab0-94ba-aba9a89aa9ae" \
    https://storage.swiftdrive.com/v1/CF_xer7_343/dogs
            
				
HTTP/1.1 200 OK
X-Container-Object-Count: 3
X-Container-Read: .r:*,.rlistings
X-Container-Bytes-Used: 252732
Accept-Ranges: bytes
Content-Length: 53
Content-Type: text/plain; charset=utf-8
X-Trans-Id: txae17dfa78da64117aaf07585a1b02115
Date: Mon, 07 Nov 2011 23:00:56 GMT

JingleRocky.jpg
RockyAndBuster.jpg
SittingBuster.jpg

			



loading table of contents...