简体   繁体   中英

Copy blob from S3 to Swift using aws-sdk gem

I have a bunch of blobs stored in Amazon S3. Ruby aws-sdk gem seems to support Swift, we just need to pass endpoint:

swift_client = Aws::S3::Resource.new(
  endpoint: 'https://swift.me.com/,
  bucket: 'bucket',
  credentials: Aws::Credentials.new(access_key_id, secret_access_key))
swift_bucket = swift_client.bucket('bucket')

s3_client = Aws::S3::Resource.new(
  region: 'us-east-1',
  bucket: 'bucket',
  credentials: Aws::Credentials.new(access_key_id, secret_access_key))
s3_bucket = s3_client.bucket('s3-bucket')

# This object exists, s3_object.exists? => true
s3_object = s3_bucket.object('SOMEUID') 
swift_object = swift_bucket.object('SOMEUID') # UID is the same as in S3
# I want to copy s3 object to swift, so I do:
swift_object.copy_from(copy_source: "#{s3_bucket.name}/#{s3_object.key}")

At this point I get "Aws::S3::Errors::NoSuchKey: The specified key does not exist.". If I do the same thing vice versa (from Swift to S3), it works fine.

Is it even possible to copy data from S3 to Swift using aws-sdk gem or should I look for another tool?

解决方案是手动复制内容,因为Swift不会在执行copy_from创建对象。

to_object.put(body: object.get.body)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM