Skip to content

Instantly share code, notes, and snippets.

@smashwilson
Created January 29, 2014 16:37
Show Gist options
  • Save smashwilson/8691847 to your computer and use it in GitHub Desktop.
Save smashwilson/8691847 to your computer and use it in GitHub Desktop.
Perform a server-side copy of a file in Cloud Files.
require 'fog'
# To connect to ServiceNet, this needs to run from a Cloud Server in the same datacenter as your
# Cloud Files containers.
service = Fog::Storage.new(
provider: 'rackspace',
rackspace_username: ENV['RAX_USERNAME'],
rackspace_api_key: ENV['RAX_API_KEY'],
rackspace_region: :ord,
rackspace_servicenet: true
)
# The target directory needs to exist beforehand.
service.directories.create key: 'test_destination'
directory = service.directories.get('test_source')
old_file = directory.files.get('oldname')
new_file = old_file.copy('test_destination', 'newname')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment