我可以在桌面设备和移动浏览器上将图片上传到Firebase Storage。但是移动浏览器不会在实时数据库中保存引用。它在桌面浏览器上。是否有必须为移动浏览器引用的特殊代码?
这里是JS代码(它是一个WIP):
$(fileButton).on('change', function(e) {
// Get file
var file = e.target.files[0];
// Create a storage reference
var storageRef = firebase.storage().ref(file.name);
// Upload file to storage bucket
var uploadTask = storageRef.put(file);
// Set uploaded file's image URL to real time database
uploadTask.on('state_changed', function(snapshot) {
var postKey = firebase.database().ref('posts/').push().key;
var imageURL = uploadTask.snapshot.downloadURL;
var updates = {};
var postData = {
url: imageURL
}
updates['posts/' + postKey] = postData;
firebase.database().ref().update(updates);
}, function(err) {
// if error
// $('.add-image-error').removeClass('hide');
console.log('There was a problem uploading the file: ' + err);
}, function() {
// if complete, reload the page
location.reload();
console.log('File successfully uploaded image and reference');
});
});