0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CarrierWave でアップロード済みのファイルを別のサーバーにアップロード

Posted at

アップロードされているファイルを別のサーバーに移行するために試したこと

# avator.file : CarrierWave::Uploader
# another_directory: Fog::Storage::AWS::Directory etc
avator = Avator.first
[avator.file, *avator.file.versions.values].compact.each do |uploader|
  file = uploader.instance_variable_get(:@file)
  another_directory.files.create(
    {
      body: file.read,
      content_type: file.content_type,
      key: uploader.path,
      public: uploader.fog_public
    }.merge(uploader.fog_attributes)
  )
end

file

CarrierWave::Uploader のインスタンス変数 @fileCarrierWave::Storage::Fog::File インスタンスがセットされているのでこれを活用する

path

CarrierWave::Uploader#path をそのまま key に使う

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?