问题描述
使用 云函数 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)
我的输出
/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
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
这篇关于无错误:无法在谷歌云存储上看到上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!