Upload of file in firebase using pyrebase return None

Viewed 54

I'm using firebase to upload images using python and pyrebase, the post request is:

@router.post('/', response_model=schemas.Product)
def add_product(
            file: UploadFile = File(),
            db: Session = Depends(get_db)
            ):
try:
    firebase = pyrebase.initialize_app(settings.config_firebase)
    storage = firebase.storage()
    path_on_cloud = "products/"+file.filename
    photo_infos = storage.child(path_on_cloud).put(file.file)
    print(firebase)  # op 1
    print(storage)   # op 2
    print(path_on_cloud)   # op 3
    print(photo_infos)   # op 4

first output (op1)

<pyrebase.pyrebase.Firebase object at 0x000001889A691790>

which means that the connection works fine

2nd:

<pyrebase.pyrebase.Storage object at 0x000001889A76A8B0>

3rd

products/baqlawa.png

4th: and here is the problem

None

the storage rules in firebase are:

rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
  allow read, write: if false;
    }
  }
}

Note: the reading request of files works fine, the problem is in uploading, and I did not using any authentication requirement.

Other thing I want to add is that in firebase console the files are added but as application/octet-stream and not jpeg or png

thank you in advance.

0 Answers
Related