google-cloud-platform - google cloud platform blob.download_to_file 文件下载位置
问题描述
gcloud beta functions deploy gcp-data-transfer --project probable-scout-216702 --runtime python37 --trigger-bucket connector-test-data-securonix --entry-point detect_file
以上是我正在使用的谷歌云功能。这是我的谷歌云存储桶上的触发器。我的 gcloud 功能正在运行,但我不知道文件应该下载到哪里。我能够将它存储在一个/tmp/
目录中,但它仍然不在我自己的系统上,我不知道/tmp
它正在下载哪个。我是使用以下代码:
def detect_file(file, context):
destination_file_name = "/Securonix/file1.txt"
f = open("/Securonix/file1.txt",'wb')
bucket = validate_message(file, 'bucket')
name = validate_message(file, 'name')
print("here")
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket)
blob = bucket.blob(name)
blob.download_to_file(f)
print('Blob {} downloaded to {}.'.format(
name,
destination_file_name))
def validate_message(message, param):
var = message.get(param)
if not var:
raise ValueError('{} is not provided. Make sure you have \
property {} in the request'.format(param, param))
return var
我收到错误:
FileNotFoundError: [Errno 2] No such file or directory: '/Securonix/file1.txt'
解决方案
然后使用/tmp/
您的文件名,这是因为您无法在除/tmp/
文件夹之外的云功能上创建文件。
你的字符串是这样的:
/tmp/Securonix/file1.txt
推荐阅读
- symfony - 设置本地端口以使用 Symfony HttpClient 发出请求
- html - 缩小联系表格
- python - 在调用 deleteLater() 后直接删除对 Qt 对象的 Python 引用是否安全?
- vue.js - 在 Nuxt 中使用来自布局的异步获取
- spring - 将数据从 Soring 启动应用程序添加到 Mondo DB
- docker - 如何缩小 Docker 磁盘映像,但在 Docker for Mac 中保留卷?
- direct3d - 如何处理 Direct3D 9Ex D3DERR_DEVICEHUNG 错误?
- node.js - npm 错误的 .pem 文件!由于代理,无法在 Windows 中安装软件包
- arrays - 使用“MPI_Gatherv”沿第 n 维堆叠数组
- spring - 如果数据库在 Spring 5 和 Hibernate 中关闭,则 Autocrate 数据库忽略错误