我发现这个文档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中进行身份验证。