1 | initial version |
You can use the Admin SDK to put a file on Firebase Storage by following these steps:
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',
});
Use the bucket()
method to obtain a reference to the Firebase Storage bucket:
const bucket = admin.storage().bucket();
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.