1

我正在尝试将存储桶中的一些内容复制到不同 aws 帐户中的存储桶。我首先将上传器对象加载到哈希中。然后我尝试连接到另一个存储桶并使用该存储桶的凭据保存资产。

    task :product_color_images => :environment do
  CarrierWave.configure do |c|
    c.fog_credentials = {
      :provider               => 'AWS',
      :aws_access_key_id      => ENV['COPY_FROM_AWS_KEY_ID'],
      :aws_secret_access_key  => ENV['COPY_FROM_AWS_KEY']
    }

    c.fog_directory = 'orig-bucket' # bucket copied from
  end

  image_storage = {}

  ProductImage.all.each do |image|
    puts 'storing product image'
    image_storage[image.id] = image.image
  end

  CarrierWave.configure do |c|
    c.reset_config
    c.fog_credentials = {
      :provider               => 'AWS',
      :aws_access_key_id      => ENV['COPY_TO_AWS_KEY_ID'],
      :aws_secret_access_key  => ENV['COPY_TO_AWS_KEY']
    }

    c.fog_directory = 'target-bucket' # bucket copied to
  end

  image_storage.each do |k, v|
    image = ProductImage.find(k)
    image.image = v
    puts 'saving product image'
    image.save
  end
end

尝试在控制台中将单个图像从一个存储桶保存到另一个存储桶会发现目标存储桶的地址未使用。

ruby-1.9.2-p290 :026 > image = ProductImage.find(197) 
ruby-1.9.2-p290 :027 > image.image = image_storage[197]
 => https://orig-bucket.s3.amazonaws.com/uploads/product_image/image/197/product_image.png 
ruby-1.9.2-p290 :028 > image.save
ruby-1.9.2-p290 :029 > image.image
 => https://orig-bucket.s3.amazonaws.com/uploads/product_image/image/197/product_image.png
4

1 回答 1

1

有时,存储桶将被授予足够的权限,同时确保您对图像具有足够的权限,以便您可以实际下载它们。

我有一个更好的解决方案给你,你可以做的是安装和配置你的 s3cmd 并在两个存储桶之间进行 rsync。这将比你的 ruby​​ on rails 做得更快。

于 2013-03-28T08:58:27.527 回答