-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
storage: cannot set object properties #536
Comments
Just an additional minor remark. |
@pdknsk Thanks for the feedback, we'll look into it. (Also thanks for hunting down a more sensible default.) |
Note that upload_from_filename overwrites any previously-set |
I applied the fix and the result is this. >>> key.content_type
'image/webp'
>>> key.upload_from_filename('dir/file.webp')
>>> key.content_type
u'application/unknown' Which is correct in a way, because that's how the object is stored online, even if incorrectly so. I tried |
I've figured out that in order to send metadata with the request it has to be set on the request body before --- a/gcloud/storage/blob.py
+++ b/gcloud/storage/blob.py
@@ -296,7 +296,7 @@ class Blob(_PropertyMixin):
}
upload = transfer.Upload(file_obj,
- content_type or 'application/unknown',
+ content_type or self.properties.get('contentType', 'application/unknown'),
total_bytes, auto_transfer=False,
chunksize=self.CHUNK_SIZE)
@@ -311,6 +311,11 @@ class Blob(_PropertyMixin):
# Use apitools 'Upload' facility.
request = http_wrapper.Request(upload_url, 'POST', headers)
+ if self.properties:
+ import json
+ headers['content-type'] = 'application/json'
+ request.body = json.dumps(self.properties)
+
upload.ConfigureRequest(upload_config, request, url_builder)
query_params = url_builder.query_params
request.url = conn.build_api_url(path=self.bucket.path + '/o', |
So the core issue here is that You could "get around this" by using |
@tseaver I'm going to send a fix and we should discuss the "right approach" in the PR. |
This is instead of using the mimetype for all files (the Python mimetypes.guess_type method is a bit limited). Fixes googleapis#536.
I haven't tried but from what I can tell 83c0fc1 only fixes |
The only difference I noticed in setting the metadata separately afterwards is that it increases metageneration version. So you wouldn't be able to make an object with metageneration And another remark on this bug. The
I haven't been able to get this to work, using |
Thanks for digging more. I filed #632 and hopefully (if we move forward on it) something like |
@pdknsk So I merged the fix, but you indicated other things are not addressed. Essentially It seems instead of blob._patch_properties(blob._properties) at the end of Or instead do you think the plan put forth in #632 is sufficient? |
I tried and it works well. It does however also set Another potential problem is that between both separate requests, the object is very briefly online with incorrect properties, I think. This could theoretically bite anyone who uses permissive |
Yeah it needs a lot of work, thanks for verifying. Hopefully #632 leads to something useable. |
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Source-Link: https://togithub.com/googleapis/synthtool/commit/d0f51a0c2a9a6bcca86911eabea9e484baadf64b Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:240b5bcc2bafd450912d2da2be15e62bc6de2cf839823ae4bf94d4f392b451dc
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Source-Link: googleapis/synthtool@352b9d4 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:3e3800bb100af5d7f9e810d48212b37812c1856d20ffeafb99ebe66461b61fc7 Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Or at least I haven't figured out how. This is how the documentation suggests it may work.
Success?
It's a lie unfortunately. (Also verified with
gsutil
).The text was updated successfully, but these errors were encountered: