0
2

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 1 year has passed since last update.

RubyでS3内の5GB以上のファイルをコピーする

Last updated at Posted at 2020-02-14

S3で5GB以上のファイルをコピーするには、普通のコピーでは出来ずMultipart Copyを使う必要があります。
RailsサーバからS3内の5GB以上のファイルを同じS3内にコピーする記事が無かったのでやり方を書きます。

gemのインストール

gem 'aws-sdk'

コピー処理

Aws::S3::Resourceのcopy_toを使用します。
Aws::S3::Clientのcopy_objectだと恐らくMultipart Copyが出来ません。

s3 = Aws::S3::Resource.new(
      region: 'reagion_name',
      access_key_id: 'access_key',
      secret_access_key: 'secret_key',
    )
bucket = s3.bucket('bucket_name')
object = bucket.object("src/file") # コピー元のobject key
object.copy_to(bucket: 'bucket_name', key: "target/file", multipart_copy: true) # コピー先のobject key

参考

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?