Using Amazon s3 boto library, how can I get the URL of a saved key?

前端 未结 3 951
执笔经年
执笔经年 2021-01-30 10:19

I am saving a key to a bucket with:

    key = bucket.new_key(fileName)
    key.set_contents_from_string(base64.b64decode(data))
    key.set_metadata(\'Content-Ty         


        
3条回答
  •  被撕碎了的回忆
    2021-01-30 11:02

    import boto
    from boto.s3.connection import S3Connection
    
    conn = S3Connection('AWS_ACCESS_KEY', 'AWS_SECRET_KEY')
    
    secure_https_url = 'https://{host}/{bucket}/{key}'.format(
        host=conn.server_name(),
        bucket='name-of-bucket',
        key='name_of_key')
    
    http_url = 'http://{bucket}.{host}/{key}'.format(
        host=conn.server_name(),
        bucket='name-of-bucket',
        key='name_of_key')
    

    That's how I did it in boto 2.23.0 for a public URL. I couldn't get the expires_in=None argument to work.

    Note that for HTTPS you can't use a subdomain.

提交回复
热议问题