【发布时间】:2018-08-24 18:44:55
【问题描述】:
uploadImage(filePath: string, camera: boolean = false) {
try {
let options: CameraOptions;
if (camera) {
options = {
quality: 40,
destinationType: this._camera.DestinationType.DATA_URL,
encodingType: this._camera.EncodingType.JPEG,
mediaType: this._camera.MediaType.PICTURE,
correctOrientation: true
}
} else {
options = {
destinationType: this._camera.DestinationType.DATA_URL,
sourceType: this._camera.PictureSourceType.PHOTOLIBRARY,
encodingType: this._camera.EncodingType.JPEG,
mediaType: this._camera.MediaType.PICTURE
}
}
this._camera.getPicture(options).then((imageData) => {
const photo = `data:image/jpeg;base64,${imageData}`;
const fileRef = this._afs.ref(filePath);
const task = fileRef.putString(photo, 'data_url');
task.snapshotChanges().pipe(
finalize(() => {
// execute other actions
fileRef.getDownloadURL().subscribe(url => {
if (url) {
this.fileUploadUrl.next(url);
}
})
let toast = this.toastCtrl.create({
message: 'Image upload successfully',
position: 'bottom',
duration: 3000
});
toast.present();
})
).subscribe();
})
} catch (e) {
console.error(e);
let toast = this.toastCtrl.create({
message: 'Image upload cancelled',
position: 'bottom',
duration: 3000
});
toast.present();
}
}
拍摄照片后(从实际的 iOS 设备)有时会崩溃,有时却可以正常工作。如果我使用前置摄像头,它总是可以工作。
但是如果我使用后置摄像头,在选择图片后,它会闪烁白屏,然后应用程序重新启动。我怀疑这是否与图像大小或分辨率有关。有时,如果我用后置摄像头拍摄了一张非常低分辨率的照片(比如在弱光环境中),它上传得很好。我在网上研究了一下,有人建议使用 --prod 标志以生产模式运行应用程序,但这并没有解决它。
我还尝试将质量值降低到一个较低的数字,但这仍然不适用于后置摄像头。
我很确定插件添加正确,隐私设置也正确,否则我将无法拍照。
【问题讨论】:
标签: ios firebase ionic-framework ionic3 google-cloud-firestore