Ask Your Question
2

How can I use Admin SDK to put a file on Firebase Storage?

asked 2022-10-23 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-01-23 12:00:00 +0000

david gravatar image

You can use the Admin SDK to put a file on Firebase Storage by following these steps:

  1. Initialize the Admin SDK with your Firebase project configuration using the following code:

    const admin = require('firebase-admin');
    
    const serviceAccount = require('path/to/serviceAccountKey.json');
    
    admin.initializeApp({
     credential: admin.credential.cert(serviceAccount),
     storageBucket: 'your-bucket-name.appspot.com',
    });
    
  2. Use the bucket() method to obtain a reference to the Firebase Storage bucket:

    const bucket = admin.storage().bucket();
    
  3. Use the upload() method on the bucket reference to upload the file to Firebase Storage:

    const filename = 'path/to/local/file.ext';
    const options = {
     destination: 'path/to/remote/file.ext',
    };
    
    await bucket.upload(filename, options);
    

    Note that the upload() method returns a Promise that fulfills when the upload has completed successfully.

That's it! Your file should now be uploaded to Firebase Storage.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-23 11:00:00 +0000

Seen: 19 times

Last updated: Jan 23 '22