Json
Json

Reputation: 670

bucket.get_blob returns None

I'm trying to follow this sample by Google on Google Cloud Platform but it does not work as expected, when I use the get_blob method, I get 'None'.

(I doubled checked the file's path and name and it is correct).

from google.cloud import storage

if __name__ == '__main__':

    storage_client = storage.Client.from_service_account_json('Motion Detector-11eeeea.json')
    bucket = storage_client.get_bucket('motion-detector-11.appspot.com')
    print ('bucket',bucket) //output: bucket, motion-detector-11.appspot.com
    zebraBlob = bucket.get_blob('/home/pi/Pictures/testimg.jpg')
    print (zebraBlob) //output: None

Running Python 2.7.9.

Please advise how to fix this.

Upvotes: 3

Views: 6542

Answers (1)

Json
Json

Reputation: 670

For all who are struggling following Google's code sample, note the few tweaks I did to make it work:

1) Make sure the relevant path is correct, my test.py is located on pi/home so the path should have been:

//Pictures//testimg.jpg

instead of

'/home/pi/Pictures/testimg.jpg'

I'm knowingly using two slashes because /t is a tab character.

2) I changed bucket.get_blob to bucket.blob

That's it, I ran the script, opened Google Cloud and there the file was.

Upvotes: 8

Related Questions