我正在尝试上传通过手机相机拍摄的照片Camera Plugin
(通过DevApp使用 Ionic 4 Native )并将其上传到Firebase Storage
. 现在我可以拍照了,但是当我上传照片时,控制台不会抛出任何错误,也不会做任何事情。最后,照片没有上传到 Firebase 存储。
这是我的代码:
.html:
<ion-button (click)="takePicture()"></ion-button>
.ts:
takePicture(){
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
var storage = firebase.storage().ref();
var photoRef = storage.child('Manager Images');
console.log(photoRef); <-- This reference is correct
let base64Image = 'data:image/jpeg;base64,' + imageData;
console.log(base64Image); <-- Returns "data:image/jpeg;base64,file:///storage/emulated/0/Android/data/io.ionic.devapp/cache/1577622281686.jpg"
// Base64 formatted string
var message = imageData;
photoRef.putString(message , 'base64', { contentType: 'image/jpg' }).then((savedPicture) => {
console.log(savedPicture.downloadURL);
});
}, (err) => {
// Handle error
});
}
我对 .putString 方法做错了吗?我参考了https://firebase.google.com/docs/storage/web/upload-files的指南,但我仍然无法让它工作。请帮忙!