Google cloud storage signed url chunked download In python?

会有一股神秘感。 提交于 2019-12-11 17:37:48

问题


I'd like to do the following functionality:

  service = get_service('storage', 'v1', auth)

  data = BytesIO()
  request = service.objects().get_media(bucket=bucket, object=filename)
  media = MediaIoBaseDownload(data, request, chunksize=chunksize)

But with a signed URL instead if a bucket and object. How do I chunk download a signed url in python?


回答1:


You can create s Signed URL either using gsutil or writing your own code to generate it. I have tested it using this:

gsutil signurl -d 10m my-key-file.json gs://my-bucket-name/my-file

After that the problem reduces to:

import urllib2
response = urllib2.urlopen('https://storage.googleapis.com/etc...')
html = response.read()

Or maybe:

from six.moves import urllib
urllib.request.urlretrieve("https://storage.goo.../etc","my-file")
print("File downloaded")

as explained in this answer.

There's also a repo where they have developed code to generate signed urls using python.



来源:https://stackoverflow.com/questions/48314092/google-cloud-storage-signed-url-chunked-download-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!