-
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: Send blob metadata in upload requests #754
Comments
yes -- if you call so i remember there was a reason that you guys didn't just want to use a generated storage client (which would handle these sorts of details for you); what was it? |
Thanks for the pointer for sending a body. As for using generated client, I don't remember there being a reason, but I'd guess it was Python 3 support and |
I expected diff --git a/gcloud/storage/blob.py b/gcloud/storage/blob.py
index ac3f9ce..c7e1336 100644
--- a/gcloud/storage/blob.py
+++ b/gcloud/storage/blob.py
@@ -340,7 +340,9 @@ class Blob(_PropertyMixin):
path=self.bucket.path + '/o')
# Use apitools 'Upload' facility.
- request = http_wrapper.Request(upload_url, 'POST', headers)
+ body = '' if not self._changes else json.dumps(self._properties)
+ request = http_wrapper.Request(url=upload_url, http_method='POST',
+ headers=headers, body=body)
upload.ConfigureRequest(upload_config, request, url_builder)
query_params = url_builder.query_params to handle it, but am getting {
"error": {
"errors": [
{
"domain": "global",
"reason": "badContent",
"message": "Unsupported content with type: application/octet-stream"
}
],
"code": 400,
"message": "Unsupported content with type: application/octet-stream"
}
} when setting
It also failed with a body of |
Also upload.ConfigureRequest(upload_config, request, url_builder) fails on a multipart upload because no content type is there: .../gcloud/storage/blob.pyc in upload_from_file(self, file_obj, rewind, size, content_type, num_retri
es)
345 headers=headers, body=body)
346
--> 347 upload.ConfigureRequest(upload_config, request, url_builder)
348 query_params = url_builder.query_params
349 base_url = conn.API_BASE_URL + '/upload'
.../_gcloud_vendor/apitools/base/py/transfer.pyc in ConfigureRequest(self, upload_config, http_request, url_builder)
533 if http_request.body:
534 url_builder.query_params['uploadType'] = 'multipart'
--> 535 self.__ConfigureMultipartRequest(http_request)
536 else:
537 url_builder.query_params['uploadType'] = 'media'
.../_gcloud_vendor/apitools/base/py/transfer.pyc in __ConfigureMultipartRequest(self, http_request)
556 # attach the body as one part
557 msg = mime_nonmultipart.MIMENonMultipart(
--> 558 *http_request.headers['content-type'].split('/'))
559 msg.set_payload(http_request.body)
560 msg_root.attach(msg) |
is |
@craigcitro No. This is not an issue when |
so if we're doing a simple or resumable upload, we just let the content-type be in the headers for the request. however, for multipart, we need the content-type for the body in order to be able to assemble the whole mime/multipart message. so it's looking in the headers for a content-type, which isn't there. where are you currently setting the content-type? can we move that up? |
It doesn't ever get put in headers. The only place it is used is in the creation of the upload = transfer.Upload(file_obj, content_type, total_bytes,
auto_transfer=False,
chunksize=self.CHUNK_SIZE) |
ah -- right, i got confused about which content-type we were looking for. the upload knows its content-type, and it'll set it. the one we're missing is the content type for the message body, which is just (normally this is done when apitools converts the proto message body into json: |
OK Cool. Pressing pause on wrestling this needlessly. Filed #755. |
Now that the migration to apitools is complete, this should be unblocked, right? |
Would love this functionality |
#3362 includes existing blob properties with the initial (or only) upload request. |
When
self._changes
is not empty, we should upgrade amedia
request to a multipart upload:whereas for resumable uploads, we should
@craigcitro Is there a way to set the body of the initial request in a resumable upload?
H/T to @pdknsk for #536
The text was updated successfully, but these errors were encountered: