首页 文章

获取已上载的blob /文件的Firebase存储令牌

提问于
浏览
1

我有一个python应用程序,它要求我将一些文件转储到Firebase存储桶中,更新一个HTML文件's img links so they point to the previously uploaded files + Token, and then save off the HTML file itself into the bucket for later use. The problem I'm,我似乎无法在Python中找到一种方法来获取blob /文件的唯一标记 . 作为参考,我一直在使用getDownloadURL在Javascript中完成此操作,它为我提供了如下所示的URL:https://firebasestorage.googleapis.com/v0/b/[project].appspot.com/o/[bucket]%2Ffile.png?alt=media&token=[token]

当我使用google-cloud-python blob方法'path'时,它为我提供了一个没有令牌的URL,我可以自己构建它:/b/[project].appspot.com/o/[bucket]%2Ffile巴纽

任何人都可以帮我指点我可以用什么方法来检索blob /文件的令牌,以便我可以构建完整的URL?

from firebase_admin import credentials
from firebase_admin import storage

try:
    cred = credentials.Certificate("serviceAccountKey.json")
    firebase_admin.initialize_app(cred, {
        'databaseURL': 'https://[project].firebaseio.com'
    })
except Exception as e:
    print str(e.message)

bucket = storage.bucket('[project].appspot.com')
blob1 = bucket.blob(userId + '/' + file)
with open(os.path.join(tmp_dir, file), 'rb') as my_file:
    blob1.upload_from_file(my_file)

#Now I need the token but this only prints the path I already know
print blob1.path

1 回答

  • 0
    bucket = storage.bucket('[project].appspot.com')
    blob1 = bucket.blob(userId + '/' + file)
    with open(os.path.join(tmp_dir, file), 'rb') as my_file:
        blob1.upload_from_file(my_file)
    
    # token here
    metadata = bucket.get_blob('path_to_new_blob').metadata
    

相关问题