简体   繁体   English

Google-cloud-storage中是否有与Python相对应的`refFromUrl`吗?

[英]Is there an equivalent to `refFromUrl` in google-cloud-storage for Python?

The Firebase API provides a convenience function Storage::refFromUrl ( source ) that converts a URL into a storage reference. Firebase API提供了便捷功能Storage :: refFromUrlsource ),可将URL转换为存储引用。

From the source (location.ts) It looks like it's a straightforward Regular expression. 源(location.ts)看来,这是一个简单的正则表达式。

Is there an equivalent Python method that works with the google-cloud-storage API to get the bucket and path? 是否存在与google-cloud-storage API一起使用的等效Python方法来获取存储区和路径?

It's a straightforward regex. 这是一个简单的正则表达式。 Here's what I put together in a few minutes, based on the reference Javascript implementation: 这是我在几分钟后根据参考Javascript实现汇总的内容:

def _urlToBucketPath (url):
    """Convert a Firebase HTTP URL to a (bucket, path) tuple, 
    Firebase's `refFromURL`.
    """
    bucket_domain = '([A-Za-z0-9.\\-]+)'
    is_http = not url.startswith('gs://')

    if is_http:
        path = '(/([^?#]*).*)?$'
        version =  'v[A-Za-z0-9_]+'
        rex = (
            '^https?://firebasestorage\\.googleapis\\.com/' +
            version + '/b/' + bucket_domain + '/o' + path)
    else:
        gs_path = '(/(.*))?$'
        rex = '^gs://' + bucket_domain + gs_path

    matches = re.match(rex, url, re.I)
    if not matches:
        raise Exception('URL does not match a bucket: %s' % url)

    bucket, _, path = matches.groups()

    if is_http:
        path = urllib.parse.unquote(path)

    return (bucket, path)

I've asked that it be added to the Firebase features list, and if it shows up I expect it'd be exposed in firebase_admin.storage 我已要求将其添加到Firebase功能列表中,如果它显示出来,我希望它会在firebase_admin.storage中公开

With the bucket and path it's straightforward to create a storage reference. 使用bucketpath可以轻松创建存储引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 google-cloud-storage Python 客户端获取下载标头? - Get download headers with google-cloud-storage Python client? 得到了一个意外的关键字参数“超时”(Python 中的 google-cloud-storage) - Got an unexpected keyword argument 'timeout' (google-cloud-storage in Python) 使用 Workload Identity Federation 对 Python 中的 Google-Cloud-Storage 进行身份验证 - Authenticate Google-Cloud-Storage in Python using Workload Identity Federation Django 2:使用 google-cloud-storage 将媒体上传到 Google Cloud Storage - Django 2: upload media to Google Cloud Storage with google-cloud-storage python google-cloud-storage库未选择活动的用户帐户 - python google-cloud-storage library does not pick active user-account 如何将超时和重试装饰器功能应用于 python 中的 google-cloud-storage 客户端? - How do I apply timeout and retry decorator functions to google-cloud-storage client in python? 使用google-cloud-storage将数据从gcs传输到s3 - Transfering data from gcs to s3 with google-cloud-storage PATCH 中的 google-cloud-storage 随机 503 错误 - google-cloud-storage random 503 error in PATCH 安装了google-cloud-storage模块0.22.0,可以自行导入,但不能作为导入导入 - Installed the google-cloud-storage module 0.22.0, Imports fine by itself but not as an import of an import google-app-engine标准中的google-cloud-storage权限被拒绝 - google-cloud-storage permission denied in google-app-engine standard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM