Skip to content
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 create copy of object version into another bucket #403

Closed
vlcinsky opened this issue Dec 12, 2015 · 5 comments
Closed

How to create copy of object version into another bucket #403

vlcinsky opened this issue Dec 12, 2015 · 5 comments
Labels
documentation This is a problem with documentation. s3

Comments

@vlcinsky
Copy link

I have versioned bucket and need to copy set of object versions into another (non versioned) bucket.

There are some SomeResource.copy_from and Client.copy_object methods.

However, I was unable to find how to specify source object version_id. The only place, where I have found CopySourceVersionId was response, but no place to put it into request.

Is there any way to copy object version into another bucket without downloading it?

With boto it was possible (but I my source bucket is having dots in names and this is not working with old boto any more.

@vlcinsky
Copy link
Author

I have found the solution.

Searching for similar problems I have found issue boto/botocore#509 I have found undocumented method to specify version id in botocore.

Testing it on boto3 I have found, it works there.

To name specific object version as SourceObject, one has to use following pattern: "/{bucket}/{key}?versionId={id}".

Now I am able to copy from specific version using boto3.

I still consider this an issue, as current version of documentation does not explain it well (it omits the version and does not explain the need to use the leading slash).

Existing specification for Object.copy_from reads for the SourceCopy parameter:

CopySource (string) -- [REQUIRED] The name of the source bucket and key name of the source object, separated by a slash (/). Must be URL-encoded.

I would propose to modify the text to clarify:

  • pattern for the CopySource (either "/{bucket}/{key}" or "/{bucket}/{key}?versionId={id}"
  • explain the url-encoded requirement - it is not clear, if it requires whole string to be url-encoded, or only the versionId or somehow differently. In my case, I did not url-encode anything.

@rayluo
Copy link
Contributor

rayluo commented Dec 17, 2015

Thanks very much for finding the solution and sharing it! We will definitely take a look into this and see how we can improve the documentation.

@rayluo rayluo added documentation This is a problem with documentation. s3 labels Dec 17, 2015
@vlcinsky
Copy link
Author

@rayluo Looking forward to that.
Yesterday I was trying to make copy of an object, having strange characters in the path (bucket-name/test/&?:/feed.txt) and did not succeed. It is either due to my misunderstanding or there is a bug.

If your updated doc explains this, it would be great. Otherwise we shall create separate issue for this particular corner case.

@kyleknap
Copy link
Member

kyleknap commented Aug 4, 2016

With the release of boto3 1.4.0, we introduced a managed copy() method that handles the copying of multipart and nonmultipart objects: https://boto3.readthedocs.io/en/latest/guide/s3.html#copies. Each of these methods make use of CopySource being a dictionary consisting of a bucket, key, and optional version id. Using this dictionary, we will create the proper CopySource key for you so you do not worry how to format or url encode the string anymore. Therefore, resolving the issue.

@kyleknap kyleknap closed this as completed Aug 4, 2016
@rajeget
Copy link

rajeget commented Sep 27, 2018

@rayluo Looking forward to that.
Yesterday I was trying to make copy of an object, having strange characters in the path (bucket-name/test/&?:/feed.txt) and did not succeed. It is either due to my misunderstanding or there is a bug.

If your updated doc explains this, it would be great. Otherwise we shall create separate issue for this particular corner case.

@vlcinsky the above problem is because of escape char , please see aws/aws-sdk-ruby#969 and draw parallel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation. s3
Projects
None yet
Development

No branches or pull requests

4 participants