I just released version 0.4.2 of the Fleakr gem which includes better support for options when uploading files. To get started, install the gem from RubyForge:
$ sudo gem install fleakr
Then make sure that you have an API key, shared secret, and auth token for the Flickr API. You can find instructions on how to do this in the Fleakr documentation (see the "Authenticated Calls" section). Once you have that data, you can configure the gem pretty quickly:
Fleakr.api_key = 'ABC123'
Fleakr.shared_secret = 'sekrit'
Fleakr.auth_token = 'DEADBEEF'
Now, let's start uploading.
Single Files
The simplest way to upload is using a single file:
photos = Fleakr.upload('/path/to/my/image.jpg')
Once uploaded, you now have a reference to the new file through the photos array. By default, this image has a title based on the filename and is only viewable to you. Let's change that:
photos = Fleakr.upload('image.jpg', :title => 'My Mug',
:viewable_by => :everyone)
This new image is available to anyone and has a customized title.
Multiple Files
In addition to specifying a path to a single file, the upload method accepts a fileglob. This way, you can push out a full directory of images in a single call:
photos = Fleakr.upload('/party/images/*.jpg', :title => 'Party Photo',
:viewable_by => :everyone)
Once the upload finishes, photos will contain a collection of the newly-uploaded images.
Additional Options
We saw how to set titles and permissions, but here are the full options that are available:
:title - Duh.
:description - The description of the image / photo.
:tags - A list of tags. This should be supplied as a single string value or an array of strings.
:viewable_by - A list of who can view this photo. Can be either :everyone or a combination of :friends and :family (e.g. :viewable_by => [:friends, :family]).
:level - The "safety level" of the photo. Can be one of :safe, :moderate, or :restricted
:type - What does this image represent? Can be one of :photo, :screenshot, or :other
:hide? - Should we hide this image from public searches? Set to true or false.
This list is also available in the documentation for Photo#upload.
Replacing Files
Remember when I said that the upload method returned a list of newly-uploaded photos? You can use that to replace the image if you'd like:
photos = Fleakr.upload('/path/to/image.jpg', :viewable_by => :everyone)
photos.first.replace_with '/path/to/other_image.jpg'
The same applies to any photo in your photoset. For example:
user = Fleakr.user('my_username')
photo = user.photos.first.replace_with('~/embarrassing_photo.jpg')
Enjoy!
Additional Resources