0
首先,我使用Polymer cli初始化Polymer應用程序抽屜模板,然後將Firebase存儲添加到Web應用程序。然後我將文件上傳代碼添加到其中一個頁面(該頁面的代碼在下面找到)。但是我收到以下錯誤(這可以防止文件被上傳,也不會更新進度條),無法將圖像上傳到Firebase存儲
Uncaught TypeError: Cannot read property 'addEventListener' of null
也
Uncaught TypeError: Cannot read property 'instanceCount' of undefined
這是我的代碼。
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="my-market">
<template>
<style>
:host {
display: block;
padding: 10px;
}
paper-card.top{
margin-top: 8px;
width: 100%;
padding-bottom: 16px;
}
</style>
<paper-card heading="Welcome to the Market!">
<div class="card-content">
<h4>Upload a photo of your item</h4>
<!--uplod image-->
<input type="file" value="upload" id="fileUpload"/>
<progress value="0" max="100" id="uploader">0%</progress>
</div>
</paper-card>
</template>
<script>
//File upload script to Firebase storage
var uploader = document.getElementById('uploader');
var fileButton = document.getElementById('fileUpload');
//File selection listener
fileButton.addEventListener('change', function(a) {
//Get image
var file = a.target.files[0];
//create a storage reference
var storageRef = firebase.storage().ref('images/' + file.name);
//store the image
var task = storageRef.put(file);
//notify the user of upload status
task.on('state_changed',
function progress(snapshot) {
var percentage = (snapshot.bytesTransferred/snapshot.totalBytes)*100;
uploader.value = percentage;
},
function error(err) {
},
function complete() {
}
);
});
</script>
<script>
Polymer({
is: 'my-market'
});
</script>
</dom-module>
我也嘗試將Firebase存儲的代碼放在index.html文件的標記中,但它仍然不起作用。有什麼建議麼?
仍然無法正常工作...還有其他想法嗎? –
相同的錯誤訊息? – Carr
是的......任何想法爲什麼? –