简体   繁体   中英

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?

要使其工作,您只需编写zebraBlob = bucket.blob('testimg.jpg')而不是zebraBlob = bucket.get_blob('testimg.jpg')

Came across the same issue and only solved it by creating another image from the Google Cloud Console first (navigate to your bucket and click " Upload file ").

Once it has been made it seems to work fine and uploads the new image, replacing the other one.

ps you can rename the image on console like this

If I figure out how to just create a new file without doing this first I will update this post, if anyone else knows already please feel free to inbox me to update it :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM