我在Amazon S3中存储了一堆blob。 Ruby aws-sdk gem似乎支持Swift,我们只需要传递端点:
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}")
此时我得到了#34; Aws :: S3 :: Errors :: NoSuchKey:指定的密钥不存在。"。如果我做相同的事情反之亦然(从Swift到S3),它工作正常。
是否可以使用aws-sdk gem将数据从S3复制到Swift,还是应该寻找其他工具?
答案 0 :(得分:0)
解决方案是手动复制内容,因为Swift不会在copy_from
执行时创建对象。
to_object.put(body: object.get.body)