【发布时间】:2019-10-14 19:00:46
【问题描述】:
我在 Cloud Function 中创建了一个 csv 文件。现在,我需要将它上传到 Cloud Storage。我将它存储在 /tmp 文件中。从那里,我必须将其上传到 Cloud Storage。
使用的代码 -
def upload_blob(bucket_name, source_file_name, 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_file(source_file_name)
print('File {} uploaded to {}.'.format(source_file_name,destination_blob_name))
final_df.to_csv('/tmp/'+file_name)
with open('/tmp/'+file_name, 'r') as file_obj:
upload_blob('test-bucket',file_obj,file_name)
但是,我面临以下错误 -
BadRequest: 400 PUT https://www.googleapis.com/upload/storage/v1/b/test-bucket/o?uploadType=resumable&upload_id=ABC: ('Request failed with status code', 400, 'Expected one of', <HTTPStatus.OK: 200>, 308)
文件存储在 /tmp 文件夹中。从那里,它没有被上传。究竟是什么错误?
【问题讨论】:
标签: python-3.x csv google-cloud-platform google-cloud-functions google-cloud-storage