使用亚马逊S3博托库,我怎么能得到一个保存的密钥的网址是什么? [英] Using Amazon s3 boto library, how can I get the URL of a saved key?
问题描述
我节省了一键一个桶:
key = bucket.new_key(fileName)
key.set_contents_from_string(base64.b64decode(data))
key.set_metadata('Content-Type', 'image/jpeg')
key.set_acl('public-read')
在保存成功,我怎样才能访问新创建的文件的网址是什么?
After the save is successful, how can I access the URL of the newly created file?
推荐答案
如果关键是公开可读(如上图所示),可以使用<一个href="http://boto.readthedocs.org/en/latest/ref/s3.html#boto.s3.key.Key.generate_url"><$c$c>Key.generate_url$c$c>:
If the key is publicly readable (as shown above) you can use Key.generate_url
:
url = key.generate_url(expires_in=0, query_auth=False)
如果该键是私有的,要生成一个URL到期共享内容的人谁没有直接访问你可以这样做:
If the key is private and you want to generate an expiring URL to share the content with someone who does not have direct access you could do:
url = key.generate_url(expires_in=300)
其中,终止
的网址是到期前的秒数。这将产生HTTPS URL的。如果preFER的HTTP URL,用这个:
where expires
is the number of seconds before the URL expires. These will produce HTTPS url's. If you prefer an HTTP url, use this:
url = key.generate_url(expires_in=0, query_auth=False, force_http=True)
这篇关于使用亚马逊S3博托库,我怎么能得到一个保存的密钥的网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!