2017-10-11 110 views
0

我試圖通過一些自定義編輯器編輯它後,捕獲的圖像上傳到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(); 
    }) 
} 

那麼,有沒有辦法用這兩種情況?

+0

你在一箇中使用file_url,在另一箇中使用data_url。在使用文件url進行測試時,是否更改了'firebase.storage.StringFormat.DATA_URL'? –

+0

@SurajRao把它改成什麼? –

回答

0

您正在將圖像保存爲數據庫中的字符串。如果您在使用使用linked api文件路徑要上傳文件(假設data_url不工作您的自定義編輯)

嘗試put()而不是putString()

return this.myPhotosRef.child(this.generateUUID()).child('myPhoto.JPEG').put(this.currentDocumentImageUri).then((savedPicture) => { 
// rest of code 
}); 
+0

謝謝,我檢查了這個,但仍然無法將圖像上傳到存儲Firebase –

+0

您是否嘗試將承諾添加到承諾和記錄錯誤? –

+0

我檢查了沒有錯誤..我認爲問題在本地路徑..我想我應該轉換它的東西,可以在firebase上傳圖像..因爲路徑如「file:/// storage/emulated。 ... JPG」 –

相關問題