Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.