Get Public URL for File - Google Cloud Storage - App Engine (Python)

前端 未结 4 1645
慢半拍i
慢半拍i 2020-12-24 15:28

Is there a python equivalent to the getPublicUrl PHP method?

$public_url = CloudStorageTools::getPublicUrl(\"gs://my_bucket/some_file.txt\", true);
         


        
4条回答
  •  无人及你
    2020-12-24 15:48

    Please refer to https://cloud.google.com/storage/docs/reference-uris on how to build URLs.

    For public URLs, there are two formats:

    http(s)://storage.googleapis.com/[bucket]/[object]
    

    or

    http(s)://[bucket].storage.googleapis.com/[object]
    

    Example:

    bucket = 'my_bucket'
    file = 'some_file.txt'
    gcs_url = 'https://%(bucket)s.storage.googleapis.com/%(file)s' % {'bucket':bucket, 'file':file}
    print gcs_url
    

    Will output this:

    https://my_bucket.storage.googleapis.com/some_file.txt

提交回复
热议问题