【发布时间】:2020-12-04 09:57:39
【问题描述】:
我目前正在从事一个使用 cordova 相机的离子项目。我可以拍摄图像,存储在离子存储中,也可以上传到 Firebase 存储。但是,图像不会保存为jpeg,而是保存为application/octet-stream。
takePicture() {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
console.log(imageData)
// Add new photo to gallery
this.photos.unshift({
data: 'data:image/jpeg;base64,' + imageData
});
// Save all photos for later viewing
this.storage.set('photos', this.photos);
//save to firebase storage
const storageRef = firebase
.storage()
.ref('photos/img.jpeg')
storageRef.putString(imageData, 'base64'), {
contentType: 'image/jpeg'
}
}, (err) => {
// Handle error
console.log("Camera issue: " + err);
});
}
【问题讨论】:
标签: javascript ionic-framework base64 cordova-plugins firebase-storage