我正在尝试将文件上传到firebase-storage,并且上传开始,因为我可以看到日志,但是随后停止。
我打开了规则,因此无论身份验证如何都可以上传。而且模拟器运行正常
var metadata = {
contentType: 'audio/*'
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
var storageRef = firebase.storage().ref();
var uploader = document.getElementById("uploader");
var fileButton = document.getElementById("music_files");
uploadBtn.addEventListener('click',function(e){
var file = document.getElementById("music_files").files;
var uploadTask = storageRef.child('music/' + file[0].name).put(file[0], metadata);
// Listen for state changes, errors, and completion of the upload.
uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'
function(snapshot) {
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log('Upload is ' + progress + '% done');
switch (snapshot.state) {
case firebase.storage.TaskState.PAUSED: // or 'paused'
console.log('Upload is paused');
break;
case firebase.storage.TaskState.RUNNING: // or 'running'
console.log('Upload is running');
break;
}
}, function(error) {
// A full list of error codes is available at
// https://firebase.google.com/docs/storage/web/handle-errors
switch (error.code) {
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
case 'storage/canceled':
// User canceled the upload
break;
case 'storage/unknown':
// Unknown error occurred, inspect error.serverResponse
break;
}
}, function() {
// Upload completed successfully, now we can get the download URL
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
console.log('File available at', downloadURL);
});
});
});
我希望日志一直保持到100%,然后才包含URL。但是现在有时候它停在30s / 40s / 50s%的位置,而其他时间开始,并且之后没有显示更多的进度(0%)