Help to upload image to firebase storage in Ionic

I’m trying to upload captured image to firebase storage after edit it by some custom editor.

Custom editor return image path such as “file:///… .jpg” so how can I upload the image by using this path ?

Here is my uploading code u may found any mistakes

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();
		})
	}

You are currently putting a string to Firebase, which is in your case only the path to the file. If you want to use putString, you need the base64 data of the image.

You can try to use the Ionic Native File Plugin and resolve the path from your image to a real image object which you could then put to Firebase!

1 Like