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.
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
Asked: 2022-10-23 11:00:00 +0000
Seen: 19 times
Last updated: Jan 23 '22
What does "Bad State" mean in relation to Flutter Firebase?
How can data be extracted from Firebase's real-time database in C# using the Firesharp library?
How can I refresh my listView once I have deleted data from the Firebase Realtime Database?
What are the broadcasting patterns for Firebase Realtime?
Where is the appropriate place to integrate Firebase Auth and Firebase Firestore user information?