我試圖通過一些自定義編輯器編輯它後,捕獲的圖像上傳到firebase存儲。如何上傳圖像與FILE_URI的distine到firebase存儲在Ionic 2
我中分2種情形的問題:
案例1:如果我用這個代碼,那麼我可以上傳圖像但我不能用我的自定義編輯器
takePicture(){ let options: CameraOptions; options = { quality : 85, destinationType: this.camera.DestinationType.DATA_URL, sourceType : this.camera.PictureSourceType.CAMERA, allowEdit : false, encodingType: this.camera.EncodingType.JPEG, correctOrientation: true, saveToPhotoAlbum: true } this.camera.getPicture(options).then((imageData) => { this.currentOriginalImageUri = 'data:image/jpeg;base64,' + imageData; this.currentDocumentImageUri = 'data:image/jpeg;base64,' + imageData; }); }
情況2:如果我使用此代碼,那麼我可以使用自定義編輯器的功能,但我無法上傳我的圖像
takePicture(){ let options: CameraOptions; options = { quality : 85, destinationType: this.camera.DestinationType.FILE_URI, sourceType : this.camera.PictureSourceType.CAMERA, allowEdit : false, encodingType: this.camera.EncodingType.JPEG, correctOrientation: true, saveToPhotoAlbum: true } this.camera.getPicture(options).then((imageData) => { this.currentOriginalImageUri = imageData; this.currentDocumentImageUri = imageData; }); }
注:這是我上傳功能
private uploadPhoto(): void {
let loader = this.loadingCtrl.create({
content: ""
})
loader.present().then(_=>{
return this.myPhotosRef.child(this.generateUUID()).child('myPhoto.JPEG').putString(this.currentDocumentImageUri,firebase.storage.StringFormat.DATA_URL).then((savedPicture) => {
this.currentDocumentImageUri = savedPicture.downloadURL;
this.afd.list('/notesImages/').push({
note_id: this.appService.id,
url: this.currentDocumentImageUri,
date: new Date().toISOString()
});
});
}).then(_=>{
loader.dismiss();
this.viewCtrl.dismiss();
})
}
那麼,有沒有辦法用這兩種情況?
你在一箇中使用file_url,在另一箇中使用data_url。在使用文件url進行測試時,是否更改了'firebase.storage.StringFormat.DATA_URL'? –
@SurajRao把它改成什麼? –