No Error: Not able to see the uploaded file on the

2019-03-06 17:34发布

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?

1条回答
戒情不戒烟
2楼-- · 2019-03-06 17:56

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

查看更多
登录 后发表回答