Edison D'souza
Edison D'souza

Reputation: 4640

Firebase Storage Web - creating reference does not work

I have tried the exact same thing given in the firebase documentation. But this is the error I get.

 functions: Failed to load functions source code. Ensure that you have
 the latest SDK by running **npm i --save firebase-functions** inside the
 functions directory.

 functions: Error from emulator. FirebaseError: Error occurred while
 parsing your function triggers.

TypeError: storage.ref is not a function
    at Object.<anonymous> (/Users/user1/projects/newproj/functions/index.js:15:26)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11
    at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:32:3)

CODE:

let firebaseApp = firebase.initializeApp(functions.config().firebase);
const storage = firebaseApp.storage();
let storageRef = storage.ref('.../abc.pdf');

IDE throws error at .ref stating that property ref does not exist on storage.

Functions Dependencies:

"dependencies": {
    "@google-cloud/functions-emulator": "^1.0.0-alpha.29",
    "express": "^4.16.1",
    "firebase": "^4.6.2",
    "firebase-admin": "^5.8.2",
    "firebase-functions": "^0.8.1",
    "grpc": "^1.9.0"
  }

Upvotes: 0

Views: 708

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599716

Your code seems to run in Cloud Functions, which is a server-side Node.js environment. There you use firebase-admin to call other Firebase services from your code.

But the FirebaseStorage.ref() method you're using comes from the Firebase Storage client-side SDK. It is not available in the Admin SDK.

To see precisely what you can use from admin.storage, have a look at the reference documentation and the Introduction to the Admin Cloud Storage API. You'll see that this documentation contains no reference to the ref() method you're trying to call.

Upvotes: 2

Related Questions