我想知道如何从上传到Firebase存储的文件中获取url? 这是我的代码:
import firebase_admin
from firebase_admin import credentials, firestore, storage
cred=credentials.Certificate('/serviceAccountKey.json')
firebase_admin.initialize_app(cred, {
'storageBucket': <my_bucket_name>
})
db = firestore.client()
bucket = storage.bucket()
blob = bucket.blob('image.jpg')
blob.upload_from_filename('/image.jpg')
#here I'd like to have url of file I uploaded
print(blob.<url>)
谢谢。
答案 0 :(得分:1)
您可以使用blob.public_url
示例代码:
bucket = storage.bucket()
blob = bucket.blob(BLOB_PATH)
blob.upload_from_filename(FILE_PATH)
print(blob.public_url)
答案 1 :(得分:1)
您应该使用以下代码:
blob.upload_from_filename(BLOB_PATH)
blob.make_public()
print(blob.public_url)
答案 2 :(得分:0)
image1 = face_recognition.load_image_file('99.jpg')
imageBlob_1 = bucket.blob('99.jpg')
imageBlob_1.upload_from_filename('99.jpg',content_type='image/jpeg')
URL_1 = imageBlob_1.public_url
response1 = requests.get(URL_1)