0

I was trying to upload an image into my firebase storage but im getting the error

Cannot read properties of undefined (reading 'child')

This is my code below

const admin = require("firebase-admin");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://url.firebaseio.com",
    storageBucket: "mybucket.appspot.com"
});

const dbStorage = admin.storage();

var uploadTask  = dbStorage.bucket().ref('/news').child(key+"/"+image).put(image, metadata);//got an error

I was trying to fixed it like

dbStorage.bucket.child() //dbStorage.bucket.ref is not a function
dbStorage.bucket().child() //dbStorage.bucket(...).ref is not a function
dbStorage.ref('/news').child() //ref is not a fucntion
Cyrille Con Morales
  • 918
  • 1
  • 6
  • 21

1 Answers1

0

The storage object in the Admin SDKs is a very thin wrapper around the underling GCP SDKs and doesn't have all conveniences that you may be used to from Firebase SDKs, such as (in this case) a child method for building a path.

Instead you will have to build the path yourself:

await bucket.upload('destination/path/in/bucket', {
  ...
});

Also see: Firebase Storage upload image file from Node.js

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • `no such file or directory, stat 'C:\Users\FGCI Administrator\Desktop\Systems\admin-incidentReport\incidentReport\path\to\Screenshot 2022-05-19 170024.png']` how i suppose to put the path ? maybe you can provide on how to – Cyrille Con Morales May 31 '22 at 14:15