Last Updated: February 25, 2016
·
1.15K
· azulinho

Batch upload of pictures to Flickr

Recently I decided to move all my photos into a new Flickr account (hey 1TB of storage).
I am a proud gnome 3 user, but I couldn't find any app that would survive the periodic outages of my crappy Virgin Media broadband.
So I decided to look up on github for some libraries I could use to upload all my pics overnight.

https://github.com/commonthread/flickr_fu is your friend here,

First go into the flickr website to generate a new API key:

http://www.flickr.com/services/api/misc.api_keys.html

create a file called flickr.yml and populate it with your flickr key and secret that you got from the URL above.

--- 
key: "yourkey"
secret: "yoursecret"
token_cache: "token_cache.yml"

then install the gem flickr_fu

gem install flickr_fu

And write a quick ruby script, named gettokencache.rb:

#!/usr/bin/env ruby
#get_token_cache.rb
require 'flickr_fu'
flickr = Flickr.new('flickr.yml')
puts 'visit the following url, then click <enter> once you have authorized:'
puts flickr.auth.url(:write)
gets
flickr.auth.cache_token

Execute it with
"ruby gettokencache.rb"
and your browser should open asking you to authenticate this app.
When its done, just click enter on the terminal and it should save the token into the token_cache.yml file.

Now create a new ruby script to upload all your pics to flickr,

#!/usr/bin/env ruby
#upload_all_mypics.rb
 require 'flickr_fu'

x = Flickr.new('flickr.yaml')
pics = Dir["#{ENV['HOME']}/Pictures/**/*"] #<- this is where my pictures are kept

pics.each do |pic|
  begin
     puts pic
     x.uploader.upload(pic)
  rescue
     puts "Dodgy pic: #{pic}"
  end
end

and execute it as:
"ruby uploadallmypics.rb"