我正在尝试将画布作为图像保存到 firebase 存储中。我已经阅读了许多有关将画布保存到服务器的文章和问题,并尝试使用以下代码实现相同的功能。
function server(){
canvas = document.getElementById("c");
var storageRef = firebase.storage().ref();
var mountainsRef = storageRef.child('mountains.jpg');
var image = new Image();
image.src = canvas.toDataURL("image/png");
var uploadTask = storageRef.child('images/' + "apple").put(image);
uploadTask.on('state_changed', function(snapshot){
// Observe state change events such as progress, pause, and resume
// See below for more detail
}, function(error) {
// Handle unsuccessful uploads
}, function() {
// Handle successful uploads on complete
// For instance, get the download URL: https://firebasestorage.googleapis.com/...
var downloadURL = uploadTask.snapshot.downloadURL;
});
}
但是当我运行 Web 应用程序时,控制台显示错误:
FirebaseError:Firebase 存储:
put
索引 0 处的参数无效:预期的 Blob 或文件。
如何成功地将画布保存到 Firebase 存储?