我正在尝试通过Firebase在我的网站上上传图像和视频,第一次上传有效,第二次上传在我的控制台上显示以下消息: firebase.js:1未捕获 {代码:“ app / duplicate-app”,消息:“ Firebase:名为'[DEFAULT]'的Firebase应用已存在(app / duplicate-app)。“,名称:” [DEFAULT]“,堆栈:” [DEFAULT] :Firebase:名为'[[DEFAULT] ...(https://code.jquery.com/jquery-3.3.1.js:4991:28)“}的Firebase应用 代码:“ app / duplicate-app” 消息:“ Firebase:名为'[DEFAULT]'的Firebase应用程序已经存在(app / duplicate-app)”。 名称:“ [DEFAULT]” 堆栈:“ [DEFAULT]:Firebase:名为'[DEFAULT]'的Firebase应用程序已经存在(app / duplicate-app)。↵在错误(https://www.gstatic.com/firebasejs/5.5.3/firebase.js:1:49452)处在Object.initializeApp(https://www.gstatic.com/firebasejs/5.5.3/firebase.js:1:48095)↵在fileInput()↵在HTMLAnchorElement。(http://xxx.tv/theme/js/js.js:115:12)↵在HTMLAnchorElement.dispatch(http://xxx.tv/theme/js/js.js:93:13)↵在HTMLAnchorElement.elemData.handle(https://code.jquery.com/jquery-3.3.1.js:5183:27)” 原型:错误另外,当我尝试上传视频不起作用时,它还会返回一条消息,提示我未发送任何数据: 未捕获e {code_:“存储/无效参数”,message _:“ Firebase存储:put中索引0处的参数无效:预期的Blob或文件。”,serverResponse_:null,name _:“ FirebaseError”}HTML: <label for="videoUpload"> <i for="videoUpload" class="material-icons videoUploadIcon">videocam</i> <input id="videoUpload" class="videoUpload" type="file" accept="video/*" style="display: none;"> </label>JS文件 $(document).ready(function(){ var config = { apiKey: "", authDomain: "web-test-.com", databaseURL: "com", projectId: ", storageBucket: ".appspot.com", messagingSenderId: "" }; firebase.initializeApp(config);}); $(function(){ $("#postBtn").on('click', function(e){ e.preventDefault(); var postField = $('#postField').val(); var image = $('#imgupload')[0].files[0]; var video = $('.videoUpload')[0].files[0]; fileInput(postField,image,video); $('#contentToUpload').hide(); $('.videoUploadIcon').show(); }); });// <!-- ADD POST -->// INPUT FILE FUNCTIONfunction fileInput(postField, image, video) { if (image != null) { uploadFile(image) } else if (video != null) { uploadFile(video) } else { console.log('youre upload cant be blank!'); }}function uploadFile(file) {var database = firebase.database();var storage = firebase.storage();const storageRef = storage.ref(); var generatedName = Math.random().toString(36).substr(2, 20); const uploadTask = storageRef.child(`images/${generatedName}`).put(file); //create a child directory called images, and place the file inside this directory uploadTask.on('state_changed', (snapshot) => { uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) { var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100; $('.progress').css("display", "block"); $('.numPercentage').css("display", "block"); $('.determinate').width(parseInt(percent) + '%'); $('.numPercentage').html(parseInt(percent) + '%'); }); }, (error) => { // Handle unsuccessful uploads console.log(error); }, () => { uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) { console.log('File available at', downloadURL); }); console.log('success'); setTimeout(function() { $('.numPercentage').fadeOut(1000).css("display", "none"); $('.determinate').fadeOut(1000).css("display", "none"); $('.progress').fadeOut(1000).css("display", "none"); $('.numPercentage').val(""); $('.determinate').val(""); }, 2000); document.getElementById("postField").value = null; document.getElementById("imgupload").value = null; document.getElementById("videoUpload").value = null; setTimeout(function() { $('.feed-posts').load('/php/posts.php').fadeIn('slow'); }, 1000); });}}// INPUT FILE FUNCTION 最佳答案 每个页面加载一次只能调用firebase.initializeApp()。现在,您每次上传时都调用它。关于javascript - Firebase Web文件上传代码:“app/duplicate-app”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52749382/