如何解决图像未另存为jpeg在Firebase存储中
我目前正在从事一个离子项目,该项目使用了科尔多瓦的相机。我能够拍摄图像,将其存储在离子存储中,还可以上传到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);
});
}
解决方法
根据API文档,putString()采用三个参数:
参数
- 数据:字符串
要上传的字符串。
- 可选格式:StringFormat
要上传的字符串的格式。
- 可选元数据:UploadMetadata
新上传对象的元数据。
第三个参数是您指定内容类型的位置。现在,您正在传递两个参数,而内容类型不属于该参数。看来您在错误的位置加上了右括号:
storageRef.putString(imageData,'base64',{
contentType: 'image/jpeg'
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。