我试图从上传本地设备到火力地堡的图像,但是当我打开网页,应该这样做,我得到这个错误,这是行不通的。我得到这个错误之前提交按钮的点击,当我打开网页出现错误。
谢谢
<div id="filesubmit">
<input type="file" id="caricaFile" class="file-select" accept="image/*"/>
<button class="file-submit">SUBMIT</button>
</div>
try{// Initialize Firebase
var config = {
apiKey: "AIzaSyA5-N-IEZDs9XYhmMCpSvyByp0OlTR-bhs",
authDomain: "hackathon-76f01.firebaseapp.com",
databaseURL: "https://hackathon-76f01.firebaseio.com",
projectId: "hackathon-76f01",
storageBucket: "hackathon-76f01.appspot.com",
messagingSenderId: "1040124036693"
};
firebase.initializeApp(config);
var storageRef = firebase.storage().ref(); // use the Blob or File API
// Create a reference to 'mountains.jpg'
var mountainsRef = storageRef.child('mountains.jpg');
// Create a reference to 'images/mountains.jpg'
var mountainImagesRef = storageRef.child('images/mountains.jpg');
var file = document.getElementById("caricaFile").value
storageRef.put(file).then(function(snapshot) {
console.log('Uploaded a blob or file!');
});
var metadata = {
contentType: 'image/jpeg',
};
// Upload the file and metadata
var uploadTask = storageRef.child('images/mountains.jpg').put(file, metadata);
}
catch(err){
console.log("errore");
console.log(err);
}
我不是否需要或不try / catch块知道,但我想它应该像这样工作:
<div id="filesubmit">
<input type="file" id="caricaFile" class="file-select" accept="image/*"/>
<button class="file-submit" onclick="fileUpload(event)">SUBMIT</button>
</div>
try{// Initialize Firebase
var config = {
apiKey: "AIzaSyA5-N-IEZDs9XYhmMCpSvyByp0OlTR-bhs",
authDomain: "hackathon-76f01.firebaseapp.com",
databaseURL: "https://hackathon-76f01.firebaseio.com",
projectId: "hackathon-76f01",
storageBucket: "hackathon-76f01.appspot.com",
messagingSenderId: "1040124036693"
};
firebase.initializeApp(config);
function fileUpload(event){
var storageRef = firebase.storage().ref(); // use the Blob or File API
var file=event.target.files[0]
storageRef.put(file).then(function(snapshot) {
console.log('Uploaded a blob or file!');
});
var metadata = {
contentType: 'image/jpeg',
};
// Upload the file and metadata
var uploadTask = storageRef.child('images/mountains.jpg').put(file, metadata);
}
}
catch(err){
console.log("errore");
console.log(err);
}