-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to copy a specified version of an object? #969
Comments
Here's one of the more probable things I've tried: source_object = Aws::S3::ObjectVersion.new({
bucket_name: "source_bucket",
object_key: "test.txt",
id: "WYIIJB3UpKixITFbqLP6nVbAJsa5Ul5F",
client: Aws::S3::Bucket.new(name: "source_bucket").client # there's probably an easier way to get a client object
})
destination_object = Aws::S3::Bucket.new("destination_bucket").object("test.txt")
source_object.copy_to(destination_object)
# NoMethodError: undefined method `copy_to' for #<Aws::S3::ObjectVersion:0x007fb7f9052d88>
destination_object.copy_from(source_object)
# ArgumentError: expected source to be an Aws::S3::Object, Hash, or String
# from .rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/aws-sdk-resources-2.1.30/lib/aws-sdk-resources/services/s3/object_copier.rb:44:in `copy_source' |
Looks like that I thought the module Aws
module S3
class ObjectCopier
def copy_source(source)
case source
when String then escape(source)
when Hash then "#{source[:bucket]}/#{escape(source[:key])}"
when S3::Object then "#{source.bucket_name}/#{escape(source.key)}"
when S3::ObjectVersion then "#{source.bucket_name}/#{escape(source.key)}?versionId=#{escape(source.id)}"
else
msg = "expected source to be an Aws::S3::Object, AWS::S3::ObjectVersion, Hash, or String"
raise ArgumentError, msg
end
end
end
end
end but now
I can't find an actual definition for I'll start down the road of submitting a raw REST request, though figuring out how to sign requests outside of this gem looks like it might be just as difficult. |
This is currently a limitation of the s3 = Aws::S3::Client.new
s3.copy_from({
bucket: 'target-bucket',
key: 'target-key',
copy_source: "source-bucket/source-key?versionId=123456789..."
}) You need to ensure the source key is correctly escaped. You can call I'll mark this issue as a feature request to add support for copying versioned IDs to the resource interfaces as a feature request. |
Ahh perfect! Thank you so much 😄 For anyone else walking down this path, check out the full documentation on that Also, it looks like you just added if !defined? Seahorse::Util.uri_path_escape
module Seahorse
module Util
class << self
def uri_path_escape(path)
path.gsub(/[^\/]+/) { |part| uri_escape(part) }
end
end
end
end
end Those are some nifty helper methods - URI escaping is always strangely confusing in Ruby. It'd be lovely if you could just do |
Added this to the feature request backlog. |
Not sure how to "vote" for feature requests, so I'll just "me too" here. |
Reopening - deprecating usage of Feature Requests backlog markdown file. |
The Amazon REST API Documentation cites the following:
I see the copy_from and copy_to methods in
Aws::S3::Object
, but I can't for the life of me figure out how to specify aversionId
in either of these requests.Am I missing something painfully obvious, or should I resort to a raw REST request?
The text was updated successfully, but these errors were encountered: