0

我发现这个文档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

问题解决了。

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

2)云SDK中登录您的Gmail

3)选择您的火力点项目

4)在控制台

gcloud auth application-default login

5.)你可以在这里看到凭证

C:\ Users \ storks \ AppData \ Roaming \ gcloud \ application_default _credentials.json

6)欲了解更多信息请参阅应用程序默认凭据是如何工作的

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