FirebaseExtended / angularfire

AngularJS bindings for Firebase
MIT License
2.73k stars 632 forks source link

uploading sanitized image file from angular2 to firebase storage #949

Closed quant-daddy closed 7 years ago

quant-daddy commented 7 years ago

I'm using angular2 DOM sanitizer to read an image file. I want to upload this file to the firebase storage. However, I am unable to find a way to convert the sanitized image to a blob or something that can be uploaded.

I'm using the function to read the image file.

readImage2(inputValue: any): Observable<any> {
    var file:File = inputValue.files[0];
    return this.ng2ImgMaxService.compress([file], this.maxImageSize).mergeMap( (result) => {
      const compressedImage = window.URL.createObjectURL(result);
      const compressedImageTrusted=this.sanitizer.bypassSecurityTrustUrl(compressedImage);
      return Observable.create((observer) => {
          observer.next({imageUrl: compressedImageTrusted});
      })
  })
}

In this code, I want to upload the compressedImageTrusted file to firebase storage. This file has a type SafeUrlImplwhich I'm not sure how to convert to something that I can upload to a firebase storage. Any help would be appreciated.

quant-daddy commented 7 years ago

I should have raised the issue in angularfire2 repo..