Skip to content

Instantly share code, notes, and snippets.

@mottaquikarim
Created April 23, 2017 06:02
Show Gist options
  • Save mottaquikarim/9a98e7c900a628e1eacf50d43c969b26 to your computer and use it in GitHub Desktop.
Save mottaquikarim/9a98e7c900a628e1eacf50d43c969b26 to your computer and use it in GitHub Desktop.
firebase storage / with storage ref creation
<!DOCTYPE html>
<html>
<head></head>
<body>
<script src="https://www.gstatic.com/firebasejs/3.8.0/firebase.js"></script>
<script>
(() => { // protect the lemmings!
// Initialize Firebase
const config = {
apiKey: "XXX-XXX",
authDomain: "XXX-XXX-XXX.firebaseapp.com",
databaseURL: "https://XXX-XXX-XXX.firebaseio.com",
projectId: "XXX-XXX-XXX",
storageBucket: "XXX-XXX-XXX.appspot.com",
messagingSenderId: "XXX"
};
firebase.initializeApp(config);
// Get a reference to the storage service, which is used to create references in your storage bucket
const storage = firebase.storage();
// Create a storage reference from our storage service
const storageRef = storage.ref();
// Create a child reference
const imagesRef = storageRef.child('images');
// imagesRef now points to 'images'
// Create a ref to a file - space.jpg
const spaceRef = imagesRef.child('space.jpg');
// ^^^ now you should have a "path" in your firebase storage that looks like: 'images/space.jpg'
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment