Код работал отлично, код загружает файл в хранилище Firebase, так как для получения загруженного файла я хочу получить URL загрузки для загруженного файла, который я также хотел бы указать, чтобы загружать только определенные форматы в хранилище, такие как jpeg png pdf et c ..
<html>
<head>
<title> firebase save</title>
<style media="screen">
body{
display : flex;
min-height: 100vh;
width : 100%;
padding : 0;
margin:0;
align-items: center;
justify-content: center;
flex-direction: column;
}
#uploader{
-webkit-appearance: none;
appearance: none;
width: 50%;
margin-bottom: 10px;
}
</style>
</head>
<body>
<progress value="0" max = "100" id="uploader" > 0%</progress>
<input type = "file" value="upload" id="fileButton" />
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
firebase initialization
};
firebase.initializeApp(config);
var uploader = document.getElementById('uploader');
var fileButton = document.getElementById('fileButton');
fileButton.addEventListener('change' , function(e) {
var file= e.target.files[0];
var storageRef = firebase.storage().ref('pics/' + file.name);
var task = storageRef.put(file);
task.on('state_changed' ,
function progress(snapshot){
var percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
uploader.value = percentage;
},
function error(err){
},
function complete(){
},
function() {
// get the uploaded image url back
uploadTask.snapshot.ref.getDownloadURL().then(
function(downloadURL) {
// You get your url from here
console.log('File available at', downloadURL);
// print the image url
console.log(downloadURL);
document.getElementById('submit_link').removeAttribute('disabled');
}
);
});
</script>
</body>
</html>
Какие изменения необходимо внести, чтобы получить URL-адрес для загрузки загруженного файла?