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

allow copy_object with content-type in metadata #738

Closed
vlcinsky opened this issue Mar 8, 2019 · 5 comments
Closed

allow copy_object with content-type in metadata #738

vlcinsky opened this issue Mar 8, 2019 · 5 comments

Comments

@vlcinsky
Copy link
Contributor

vlcinsky commented Mar 8, 2019

Trying to use copy_object to copy an object from one bucket to another.

To keep the target object well functional, I need to preserve Content-Type and Content-Encoding headers.

Content-Encoding is possible passing it's value via metadata.

However, I did not succeed with Content-Type.

The only solution was to edit sources of minio/helpers.py function is_supported_header adding value "content-type".

# returns true if a standard supported header
def is_supported_header(key):
    ## Supported headers for object.
    supported_headers = [
       "cache-control",
       "content-encoding",
       "content-type",  # added one
       "content-disposition",
       "content-language",
       "x-amz-website-redirect-location",
            ## Add more supported headers here.
        ]
    return key.lower() in supported_headers

This might be the solution, but I am not sure, it does not break anything else.

@poornas
Copy link
Contributor

poornas commented Mar 8, 2019

@vlcinsky , source metadata will be copied automatically to destination if you leave metadata as None in the copy_object call. You should pass metadata in the api call only if it is your intention to replace metadata in the source object.

copy_result = client.copy_object("testbucket", "test/image2.jpg",
                                     "testbucket/test/image1.jpg",
                                     copy_conditions)

@vlcinsky
Copy link
Contributor Author

vlcinsky commented Mar 9, 2019

@poornas thanks, I confirm your suggestion to leave setting metadata copied source content-type and content-encoding to target object (I did not use copy_condition too, but this is probably irrelevant).

For my use case this works well now. Thanks a lot.

In other cases, when user copying object and trying to fix content-type e.g. from text/xml to application/xml it would still be an issue.

@poornas
Copy link
Contributor

poornas commented Mar 9, 2019

s3 CopyObject api allows you to entirely replace the metadata or retain the existing metadata on source side at destination, not both. If you want to keep some of the metadata at source and also add different metadata headers - then application needs to first do a stat of the object and get the metadata, then pass it in your copy_object with modifications you might need.

@vlcinsky
Copy link
Contributor Author

vlcinsky commented Mar 9, 2019

@poornas the concept you describe is clear and I like it (either implicitly copy all metadata or explicitly define all).

Anyway, attempting to change content-type failed while with content-encoding it succeeded. So the current implementation does not completely follow the concept.

See the PR #739. It allows modifying content-type via metadata, but test case https://github.com/minio/minio-py/blob/master/tests/unit/header_value_test.py#L24 is rejecting such an option.

@poornas
Copy link
Contributor

poornas commented Mar 9, 2019

you are right @vlcinsky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants