Dav*_*ris 11 python google-cloud-storage google-cloud-platform google-cloud-functions serverless
我正在尝试从云功能中将文件上传到谷歌云存储.但是,我无法将云存储库导入到我的函数中.
可以通过这种方式从云功能中使用云存储吗?
from google.cloud import storage
def upload_blob(bucket_name, blob_text, destination_blob_name):
"""Uploads a file to the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_string(blob_text)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
def log_data(request):
request_json = request.get_json()
BUCKET_NAME = 'my-bucket'
BLOB_NAME = 'test-blob'
BLOB_STR = '{"blob": "some json"}'
upload_blob(BUCKET_NAME, BLOB_STR, BLOB_NAME)
return f'Success!'
Run Code Online (Sandbox Code Playgroud)
Deployment failure:
Function load error: Code in file main.py can't be loaded.
File "/user_code/main.py", line 1, in <module>
from google.cloud import storage
ImportError: cannot import name 'storage' from 'google.cloud' (unknown location)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4254 次 |
| 最近记录: |