Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError 'NoneType' object has no attribute 'upload_from_filename'

I'm using Python 2.7.9 on Linux and I am following Google's example on Google-Cloud Server SDK. My goal is to upload an image to Google Cloud Platform, but I'm getting the error below.

File "/home/pi/test.py", line 15, in <module>
  zebraBlob.upload_from_filename(filename='/home/pi/Pictures/testimg.jpg')
AttributeError: 'NoneType' object has no attribute
  'upload_from_filename'

Code:

from firebase import firebase
from google.cloud import storage
import os

firebase = firebase.FirebaseApplication('https://motion-detector-234.firebaseio.com', None)
storage_client = storage.Client.from_service_account_json('Motion Detector-8gf5445fgeeea.json')

bucket = storage_client.get_bucket('motion-detector-210fds717.appspot.com')
print ('bucket', bucket) // output: bucket, motion-detector-210717.appspot.com

zebraBlob = bucket.get_blob('testimg.jpg')
print(zebraBlob) // output: None

zebraBlob.upload_from_filename(filename='/home/pi/Pictures/testimg.jpg')

How can it be resolved?

like image 378
Json Avatar asked Sep 02 '25 15:09

Json


1 Answers

To make it work you should simply write zebraBlob = bucket.blob('testimg.jpg') instead of zebraBlob = bucket.get_blob('testimg.jpg')

like image 133
fenske Avatar answered Sep 05 '25 11:09

fenske