. .

tutorial

Using the Amazon Cloud with Smalltalk

September 27, 2010 15:06:13.021

One of the cooler packages in the public store repository is Cloudfork - to get it, just load "Cloudfork-all" into VisualWorks or ObjectStudio. from there, and then you can access whatever cloud services you use on Amazon. You'll need key info (you get that from Amazon), and you'll need something actually stored there. From there:


"get access"
credentials := CFAWSCredentials newWith: key andSecret: secret.
s3 := CFSimpleStorageService newWith: credentials.

Now that you have your credentials lined up, you can query the buckets you have on S3:


"get buckets"
buckets := (s3 allBuckets) result.
Transcript clear.
buckets do: [:each |
	Transcript show: 'Bucket: <', each name, '>'.
	Transcript cr].

Now open up a bucket and see what's inside it:


"open a bucket"
bucket := s3 openBucketNamed: 'jar-images'.
all := bucket getList result.

Finally, now get an item and have a look at it. In my case, it's a JPEG:


"now extract first item"
key := all first key.
byteArray  := (bucket getObject: key) result.

"save to a file"
file := 'imgFroms3.jpg' asFilename writeStream.
file binary.
file nextPutAll: byteArray.
file close.

"now open it"
img := (ImageReader fromFile: 'imgFroms3.jpg') image.

And that's it. I did a screencast on this awhile back as well:

Technorati Tags: , , ,

posted by James Robertson

 Share Tweet This