我正在尝试将图像上传到Firebase,但出现错误。我正在使用python 3.6.1

时间:2019-04-26 17:57:45

标签: python

import firebase_admin
from firebase_admin import credentials,firestore
from firebase_admin import storage
from google.cloud import storage
from google.cloud.storage import client

cred = credentials.Certificate('a.json')
firebase_admin.initialize_app(cred, {
    'storageBucket': 'gs://test-e8fcf.appspot.com/'
})
buck=storage.storage()

blob = buck.blob('F:/b.PNG')
blob.upload_from_filename(filename='F:/b.PNG')

我遇到错误:

    buck=storage.storage()
AttributeError: 'function' object has no attribute 'storage'

2 个答案:

答案 0 :(得分:0)

import firebase
from google.cloud import storage
from google.cloud.storage import client
import cv2

import firebase_admin
from firebase_admin import credentials
from firebase_admin import storage

currentImage = None
firebase = firebase.FirebaseApplication('https://auburnfirebase.firebaseio.com', None)

imageUrl = "imageurlkalyan.com"
firebase.delete('/image',None)
result = firebase.post('/image',imageUrl)

cred = credentials.Certificate('storageServiceAuburn.json')
firebase_admin.initialize_app(cred, {
    'storageBucket': 'auburnfirebase.appspot.com'
})

bucket = storage.bucket()
print bucket

img = cv2.imread('photo.png')
#cv2.imshow('image',img)

imageBlob = bucket.blob(os.path.basename('C:/Python27/photo.png'))
print imageBlob

Upload Image file to Firebase in Python

答案 1 :(得分:0)

# Import gcloud
from google.cloud import storage

# Enable Storage
client = storage.Client()

# Reference an existing bucket.
bucket = client.get_bucket('projectid.appspot.com')

# Upload a local file to a new file to be created in your bucket.
zebraBlob = bucket.get_blob('zebra.jpg')
zebraBlob.upload_from_filename(filename='/photos/zoo/zebra.jpg')

How to upload images to Firebase from Raspberry Pi?