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

Support XML API for Resumable Upload #60

Open
anshulpatel25 opened this issue Feb 6, 2019 · 4 comments
Open

Support XML API for Resumable Upload #60

anshulpatel25 opened this issue Feb 6, 2019 · 4 comments
Labels
api: storage Issues related to the googleapis/google-resumable-media-python API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@anshulpatel25
Copy link

Expected Behavior

  1. Generate signed URL using gsutil.
gsutil signurl -d 500m  -c 'text/plain' \
    -m RESUMABLE ~/Downloads/key.json \
    gs://<gcs_bucket>/<file_name>.txt
  1. Use the signed URL with ResumableUpload
upload = ResumableUpload(signed_url, 1024*1024)
transport = session = Session()
response = upload.initiate(transport, stream, metadata, "text/plain", total_bytes=total_bytes)  
  1. Upload should execute initiate method without giving an error and return the response object.

Actual Behavior

  1. Generate signed URL using gsutil.

gsutil signurl -d 600m ~/Downloads/key.json gs://<gcs_bucket>/<file_name>.txt.

  1. Use the signed URL with ResumableUpload
upload = ResumableUpload(signed_url, 1024*1024)
response = upload.initiate(transport, stream, metadata, "text/plain", total_bytes=total_bytes) # transport = session = Session()
  1. Getting the following exception
Traceback (most recent call last):
  File "upload_test.py", line 19, in <module>
    response = upload.initiate(transport, stream, metadata, "text/plain", total_bytes=total_bytes)
  File "/Users/anshul.patel/.local/share/virtualenvs/virtualenv-python-domIBOZP/lib/python3.7/site-packages/google/resumable_media/requests/upload.py", line 327, in initiate
    self._process_initiate_response(result)
  File "/Users/anshul.patel/.local/share/virtualenvs/virtualenv-python-domIBOZP/lib/python3.7/site-packages/google/resumable_media/_upload.py", line 451, in _process_initiate_response
    response, u'location', self._get_headers)
  File "/Users/anshul.patel/.local/share/virtualenvs/virtualenv-python-domIBOZP/lib/python3.7/site-packages/google/resumable_media/_helpers.py", line 64, in header_required
    response, u'Response headers must contain header', name)
google.resumable_media.common.InvalidResponse: ('Response headers must contain header', 'location')

It seems like the ResumableUpload doesn't interpret XML API endpoint.

Specifications

  • Version: 3.7
  • Platform: macOS Mojave 10.14.2
@antoncohen
Copy link

I think the key thing here is that the XML API requires the header x-goog-resumable: start, while the JSON API doesn't. If ResumableUpload.initiate() set the header x-goog-resumable: start it would work with the XML API. As far as I know the XML API is the only way to do signed URLs.

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Feb 6, 2019
@sduskis sduskis added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 2, 2019
@tseaver
Copy link
Contributor

tseaver commented Aug 28, 2019

@anshulpatel25 Does the upload work for you if you pass in the appropriate header to the constructor, e.g.:

xml_api_headers = {'x-goog-resumable': 'start'}
upload = ResumableUpload(signed_url, 1024*1024, headers=xml_api_headers)
response = upload.initiate(transport, stream, metadata, "text/plain", total_bytes=total_bytes)

@anshulpatel25
Copy link
Author

anshulpatel25 commented Aug 29, 2019

Hey @tseaver

Only adding {'x-goog-resumable': 'start'} doesn't work, I also required to add content-type for it to work.

Working

>>> xml_api_headers
{'x-goog-resumable': 'start', 'content-type': 'text/plain'}
>>> upload = ResumableUpload(signed_url, 1024*1024, headers=xml_api_headers)
>>> p = upload.initiate(transport, stream, metadata, file_content_type)
......
HTTP/1.1" 201 0

Not Working

>>> xml_api_headers
{'x-goog-resumable': 'start'}
>>> upload = ResumableUpload(signed_url, 1024*1024, headers=xml_api_headers)
>>> x = upload.initiate(transport, stream, metadata, file_content_type)
......
google.resumable_media.common.InvalidResponse: ('Response headers must contain header', 'location')

Thanks

@tseaver
Copy link
Contributor

tseaver commented Aug 29, 2019

@anshulpatel25 Thanks for the research! Looks like #99 needs a different approach, as the Content-Type for the JSON API is required to be 'application/json; charset=UTF-8' (the metadata is sent with the initiate request as JSON).

See the XML API docs for requirements:

  • Empty body (no metadata).
  • Content-Length: 0 header.
  • x-goog-resumable: startheader
  • Optional Content-Type: <XXX> header.

@tseaver tseaver removed their assignment Aug 29, 2019
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/google-resumable-media-python API. label Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/google-resumable-media-python API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants