图像未在 firebase 存储中保存为 jpeg
Image not saved as jpeg in firebase storage
我目前正在从事一个使用 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);
});
}
根据 API 文档,putString() 采用三个参数:
Parameters
- data: string
The string to upload.
- Optional format: StringFormat
The format of the string to upload.
- Optional metadata: UploadMetadata
Metadata for the newly uploaded object.
第三个参数是您指定内容类型的地方。现在,您正在传递两个参数,内容类型不是其中的一部分。右括号似乎放错地方了:
storageRef.putString(imageData, 'base64', {
contentType: 'image/jpeg'
});
我目前正在从事一个使用 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);
});
}
根据 API 文档,putString() 采用三个参数:
Parameters
- data: string
The string to upload.
- Optional format: StringFormat
The format of the string to upload.
- Optional metadata: UploadMetadata
Metadata for the newly uploaded object.
第三个参数是您指定内容类型的地方。现在,您正在传递两个参数,内容类型不是其中的一部分。右括号似乎放错地方了:
storageRef.putString(imageData, 'base64', {
contentType: 'image/jpeg'
});