Last active
July 18, 2016 15:25
-
-
Save the-dagger/64210098038445eb35441ad3c8c39061 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
<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script> | |
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> | |
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script> | |
<script> | |
var $ = jQuery; | |
var timestamp = Number(new Date()); //this will server as a unique ID for each user | |
var form = document.querySelector("form"); | |
var config = { | |
apiKey: "API_KEY", | |
authDomain: "app-id.firebaseapp.com", | |
databaseURL: "https://app-id.firebaseio.com", | |
storageBucket: "app-id.appspot.com", | |
}; | |
firebase.initializeApp(config); | |
var database = firebase.database(); | |
form.addEventListener("submit", function(event) { | |
event.preventDefault(); | |
var ary = $(form).serializeArray(); | |
var obj = {}; | |
for (var a = 0; a < ary.length; a++) obj[ary[a].name] = ary[a].value; | |
console.log("JSON",obj); | |
var file_data = $('#uploadZip').prop('files')[0]; | |
var storageRef = firebase.storage().ref(timestamp.toString()); | |
storageRef.put(file_data); | |
var form_data = new FormData(); | |
form_data.append('file', file_data); | |
firebase.database().ref('users/' + timestamp).set(obj); | |
database.ref('users/' + timestamp).once('value').then(function(snapshot) { | |
console.log("Received value",snapshot.val()); | |
)}; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment