Search code examples
ruby-on-railsrubyrackspace

rackspace private containers via fog gem


I'm looking for someone who can give me some tips - or, ideally, knows where to find a step-by-step guide or something - for working with private rackspace containers (via temp URL) using Fog in a Rails app. I've got fairly far using just their documentation, but none of the temp URLs I generate seem to be valid (401 errors).

Anyone have any tips? I know this is fairly vague, but was hoping there might be a comprehensive guide out there or something - wasn't able to find one via googling around.

Thanks!

EDITED

So in response to a comment, I tried following the directions from the getting started guide exactly. When I go to the URL returned by the code below, I get ERR_CONNECTION_REFUSED. Any ideas?

require "fog"

@storage = Fog::Storage.new(:rackspace_username     => '{myUsername}',
                            :rackspace_api_key      => '{myAPIKey}',
                            :rackspace_region      => '{myRegion}',
                            :provider               => 'Rackspace')

directory = @storage.directories.get('{myContainer}')

directory.public = false
directory.save

file = directory.files.create(
  :key => 'somefile.txt',
  :body => 'Rackspace is awesome!'
)

account = @storage.account
account.meta_temp_url_key = '{myTempUrlKey}'
account.save

@storage = Fog::Storage.new(:rackspace_username     => '{myUsername}',
                            :rackspace_api_key      => '{myAPIKey}',
                            :rackspace_region       => '{myRegion}',
                            :rackspace_temp_url_key => '{myTempUrlKey}',
                            :provider               => 'Rackspace')

directory = @storage.directories.get('{myContainer}')

file = directory.files.get('somefile.txt')

temp_url = file.url(Time.now.to_i + 1000000)

puts temp_url

Solution

  • SOLVED

    By getting rid of the directory, file, and temp_url variables at the end and instead using

    @storage.get_object_https_url('{myContainer}', 'somefile.txt', Time.now + 60)
    

    which was found in the fog source here.