Created
November 16, 2017 12:45
-
-
Save Darmaal/ee585d3dface36e197437b07bf305f22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>storage</title> | |
<link rel="stylesheet" type="text/css" href="index.css"> | |
</head> | |
<body> | |
<div id="centereveryone"> | |
<progress value="0" max="100" id="uploader">0%</progress> | |
<input type="file" value="upload" id="uploadButton"/> | |
</div> | |
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script> | |
<script> | |
// Initialize Firebase | |
var config = { | |
apiKey: "AIzaSyDsIkYEJWhaX5lIFyC-cwJmxCbDZZGHGNo", | |
authDomain: "maurice-b38b2.firebaseapp.com", | |
databaseURL: "https://maurice-b38b2.firebaseio.com", | |
projectId: "maurice-b38b2", | |
storageBucket: "maurice-b38b2.appspot.com", | |
messagingSenderId: "716599781292" | |
}; | |
firebase.initializeApp(config); | |
var uploader = document.getElementById('uploader'); | |
var btn = document.getElementById('uploadButton'); | |
if(btn){ | |
btn.addEventListener('change', function(e) { | |
var file = e.target.files[0]; | |
var storageRef = firebase.storage().ref('someImgFolder/' + file.name); | |
var task = storageRef.put(file); | |
task.on('state_changed', | |
function progress(snapshot){ | |
var pc = (snapshot.bytesTransferred / snapshot.totalBytes ) * 100 ; | |
uploader.value = pc; | |
}, | |
function error(err){ | |
alert("errr : " + err); | |
}, | |
function complete(){ | |
alert("uploaded successfully !!!"); | |
} | |
); | |
}); | |
} else { | |
console.log("btn is undefined...!"); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment