Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  177] [ 2]  / answers: 1 / hits: 5703  / 4 Years ago, thu, october 15, 2020, 12:00:00

I would like to use storage service from Firebase with a nodeJS api (hosted on "firebase functions") to allow the users to upload his avatars.


So I read the doc from https://firebase.google.com/docs/storage/web/start


and I do:


admin.js


const admin = require('firebase-admin');
const config = require('./config.js');

admin.initializeApp(config);

const db = admin.firestore();
const storage = admin.storage();

module.exports = { admin, db, storage };

user.js


const { admin, db, storage } = require('../util/admin');

exports.postAvatar = async (request, response) => {

const storageRef = storage.ref();

}

but I have the following error: storage.ref is not a function


Is something is missing from the documentation ?


The console.log of storage const is:


Storage {
INTERNAL: StorageInternals {},
storageClient: Storage {...},
appInternal: FirebaseApp {...}
}

More From » node.js

 Answers
3

admin.storage() returns a Storage object. If you want to use it to refer to a file in your default storage bucket, you should use its bucket() method with no parameters, and it will give you a Bucket object from the Google Cloud nodejs SDK.


There are no methods called ref() anywhere in that SDK. It's not much like the JavaScript web client SDK. You will have to learn a different but similar API to work with content in using the Cloud Storage node SDK. The Admin SDK just essentially wraps this API.


const file = storage.bucket().file('/path/to/file');

[#2485] Sunday, October 11, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deiong

Total Points: 15
Total Questions: 103
Total Answers: 99

Location: Sudan
Member since Thu, May 7, 2020
4 Years ago
deiong questions
Mon, Nov 22, 21, 00:00, 3 Years ago
Tue, Jun 15, 21, 00:00, 3 Years ago
Mon, Dec 21, 20, 00:00, 3 Years ago
Tue, Jul 21, 20, 00:00, 4 Years ago
;