Firebase将图像从python上传到firebase-storage

时间:2017-03-07 18:32:03

标签: python python-3.x firebase firebase-authentication firebase-storage

我找到了这个文档https://firebase.google.com/docs/storage/gcp-integration#apis

以下是此文档的代码

# Import gcloud
from google.cloud import storage

# Enable Storage
client = storage.Client()

# Reference an existing bucket.
bucket = client.get_bucket('my-existing-bucket')

# Upload a local file to a new file to be created in your bucket.
zebraBlob = bucket.get_blob('zebra.jpg')
zebraBlob.upload_from_filename(filename='/photos/zoo/zebra.jpg')

# Download a file from your bucket.
giraffeBlob = bucket.get_blob('giraffe.jpg')
giraffeBlob.download_as_string()

排队client = storage.Client()

说:

  

无法自动确定凭据。请设置GOOGLE_APPLICATION_CREDENTIALS或明确创建凭据并重新运行应用程序

下一步我就放

from oauth2client.client import GoogleCredentials
GOOGLE_APPLICATION_CREDENTIALS = 'credentials.json'
credentials = GoogleCredentials.get_application_default()

说:

  

应用程序默认凭据不可用。如果在Google Compute Engine

中运行,则可以使用它们

我的最后一个问题是如何在Google Compute Engine中进行身份验证。

1 个答案:

答案 0 :(得分:1)

问题解决了。

1。)您需要安装https://cloud.google.com/sdk/

2。)使用你的Gmail登录云端sdk

3.)选择你的火力棒项目

4.)将gcloud auth application-default login放入控制台

5.)您可以在此处查看凭据

C:\用户\鹳\应用程序数据\漫游\ gcloud \ application_default_credentials.json

6。)有关详细信息,请参阅应用程序默认凭据的工作原理

https://developers.google.com/identity/protocols/application-default-credentials