<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Learn how to use the Firebase platform on the Web">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Firebase</title>
</head>
<body>
<form id="image-form" action="#">
<input id="mediaCapture" type="file" accept="image/*">
<button type="button" onclick="ss()">aaa</button>
</form>
<!-- Firebase -->
<script src="js/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyCfV0A1Q-Ln-evzUScnnq_kLedOB0BAl7Q",
authDomain: "fbtest-d047e.firebaseapp.com",
databaseURL: "https://fbtest-d047e.firebaseio.com",
storageBucket: "fbtest-d047e.appspot.com",
};
firebase.initializeApp(config);
// Get a reference to the storage service, which is used to create references in your storage bucket
function ss() {
var storage = firebase.storage();
var storageRef = firebase.storage().ref();
var metadata = {
contentType: 'image/jpeg',
};
var file = document.getElementById('mediaCapture').files[0];
// Upload the file and metadata
var uploadTask = storageRef.child('mountains.jpg').put(file, metadata);
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// See below for more detail
}, function(error) {
// Handle unsuccessful uploads
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
var downloadURL = uploadTask.snapshot.downloadURL;
console.log(downloadURL);
});
}
</script>
</body>
</html>