No Error: Not able to see the uploaded file on the google cloud storage(无错误:无法在谷歌云存储上看到上传的文件)
问题描述
使用 云函数 python 在云函数上运行 python 代码.p>
我正在处理云上的图像.现在我想将该图像保存在 google-cloud-storage
从 google.cloud 导入存储导入简历2从临时文件导入 NamedTemporaryFile导入操作系统客户端 = 存储.客户端()bucket = client.get_bucket('document')图像 = cv2.imread('15.png')使用 NamedTemporaryFile() 作为临时:打印(类型(temp.name),",temp.name)iName = "".join([str(temp.name),".jpg"])打印(iName)cv2.imwrite(iName,image)打印(os.path.exists(str(iName)))blob = bucket.blob('document/Test15.jpg')blob.upload_from_filename(iName)
我的输出
<块引用><类'str'>
/var/folders/5j/bqk11bqj4r55f8975mn__72m0000gq/T/tmplcgzaucx
/var/folders/5j/bqk11bqj4r55f8975mn__72m0000gq/T/tmplcgzaucx.jpg
是的
不知道怎么回事
谁能提出解决方案?
愚蠢的错误,结果
blob = bucket.blob('document/Test15.jpg')
在桶 document
document
所以实际路径是 document/document/Test15.jpg
Have a python code running on cloud function using cloud function python.
I'm processing an image on cloud. Now I want to save that image on google-cloud-storage
from google.cloud import storage
import cv2
from tempfile import NamedTemporaryFile
import os
client = storage.Client()
bucket = client.get_bucket('document')
image = cv2.imread('15.png')
with NamedTemporaryFile() as temp:
print(type(temp.name)," ",temp.name)
iName = "".join([str(temp.name),".jpg"])
print(iName)
cv2.imwrite(iName,image)
print(os.path.exists(str(iName)))
blob = bucket.blob('document/Test15.jpg')
blob.upload_from_filename(iName)
My output
< class 'str' >
/var/folders/5j/bqk11bqj4r55f8975mn__72m0000gq/T/tmplcgzaucx
/var/folders/5j/bqk11bqj4r55f8975mn__72m0000gq/T/tmplcgzaucx.jpg
True
Don't know what's going wrong
can anyone suggest a solution?
Silly mistake, turns out
blob = bucket.blob('document/Test15.jpg')
creates another folder document
inside the bucket document
so the actual path would be document/document/Test15.jpg
这篇关于无错误:无法在谷歌云存储上看到上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无错误:无法在谷歌云存储上看到上传的文件
基础教程推荐
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01