问题描述
我目前正在从事一个离子项目,该项目使用了科尔多瓦的相机。我能够拍摄图像,将其存储在离子存储中,还可以上传到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'
});