我發現這個文檔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中進行身份驗證。