2017-10-11 16 views
0

캡처 된 이미지를 일부 사용자 지정 편집기로 편집 한 후 Firebase 저장소에 업로드하려고합니다.FILE_URI와 이미지를 이오니아 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 :이 코드를 사용한 경우 사용자 정의 편집기 의 기능을 사용할 수 있지만 이미지를 업로드 할 수 없습니다.

    ,210
    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입니다. file url로 테스트하는 동안'firebase.storage.StringFormat.DATA_URL'을 변경 했습니까? –

+0

@SurajRao 무엇으로 변경하나요? –

답변

0

이미지를 데이터베이스에 문자열로 저장하고 있습니다. 당신이 (사용자 정의 편집기 작동하지 않는 가정 data_url)를 linked api을 사용하여 파일 경로를 사용 업로드 파일하려면

put() 대신 putString()보십시오.

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

고맙습니다, 이걸 확인했는데 이미지가 저장소 파이어베이스에 업로드되지 않습니다 –

+0

약속에 캐치를 추가하고 오류를 기록해 보았습니까? –

+0

내가 거기에 아무런 오류가 없습니다 .. 내가 생각하는 로컬 경로에 문제가 .. 내가 firebase에 이미지를 업로드 할 수있는 뭔가를 변환해야한다고 생각 .. 경로와 같은 "file : /// storage/emulated. ... jpg " –