【发布时间】:2019-03-12 20:20:17
【问题描述】:
我无法将图片上传到 Firebase。任何帮助将不胜感激。
有人熟悉如何在 Ionic 4.0 中将图片上传到 firebase 吗?下面是用于在 Ionic 2 中工作的代码,但是现在当我单击按钮将图像上传到 firebase 时,响应(单击)大约需要 30 秒,然后它永远不会将图像上传到 firebase。
我尝试使用本教程中的示例,但无法摆脱与 ImagePicker 相关的错误。 https://ionicthemes.com/tutorials/about/ionic-firebase-image-upload 任何帮助将不胜感激。
<ion-card-content>
<div>
<img src="assets/img/add-an-image.png" (click)="selectPhoto()"/>
</div>
</ion-card-content>
constructor(
private afAuth: AngularFireAuth,
private camera: Camera) {
this.afAuth.authState.subscribe(user => {
this.userId = user.uid;
this.myPhotosRef = firebase.storage().ref(`/Photos/${ this.userId }/`);
});
}
selectPhoto(): void {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
};
this.camera.getPicture(options).then((imageData) => {
console.log(options, 'get pic');
this.myPhoto = imageData;
this.uploadPhoto(this.myPhoto);
}, error => {
console.log('ERROR -> ' + JSON.stringify(error));
});
}
private uploadPhoto(photoName: string): void {
this.myPhotosRef.child(photoName)
.putString(this.myPhoto, 'base64', { contentType: 'image/png' })
.then((savedPicture) => {
this.myPhotoURL = savedPicture.downloadURL;
});
}
【问题讨论】:
-
要求我们推荐或查找书籍、工具、软件库、教程或其他场外资源的问题对于 Stack Overflow 来说是无关紧要的,因为它们往往会吸引固执己见的答案和垃圾邮件。相反,请描述问题以及迄今为止为解决该问题所做的工作。
-
你说,
"I tried using the example in this tutorial"。你指的是什么教程?