# Ionic File Chooser with upload to Firebase functionality

**URL:** <https://forum.ionicframework.com/t/ionic-file-chooser-with-upload-to-firebase-functionality/128682>\
**Category:** ionic-v3\
**Created:** [April 23, 2018, 7:21pm UTC](https://forum.ionicframework.com/t/ionic-file-chooser-with-upload-to-firebase-functionality/128682 "2018-04-23T19:21:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmcgowan94](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@bmcgowan94](https://forum.ionicframework.com/u/bmcgowan94)\
**Post date:** [April 23, 2018, 7:21pm UTC](https://forum.ionicframework.com/t/ionic-file-chooser-with-upload-to-firebase-functionality/128682/1 "2018-04-23T19:21:02Z")

</div>

Hi there,

I’ve recently started to try and use the file chooser in ionic.  
I want it so that the user can choose a picture from their gallery, to then upload to firebase storage.

Here is my code…

```auto
 // This function allows users to upload a profile photo from their gallery
  uploadFromGallery()
  {
    this.fileChooser.open().then((uri) => {
        alert(uri);

        this.file.resolveLocalFilesystemUrl(uri).then((newUrl) => {
          alert(JSON.stringify(newUrl));

          let dirPath = newUrl.nativeURL;
          let dirPathSegments = dirPath.split('/'); //breaks string into array 
          dirPathSegments.pop(); // remove last element 
          dirPath = dirPathSegments.join('/');

          this.file.readAsArrayBuffer(dirPath, newUrl.name).then(async (buffer) => {
            await this.upload(buffer, newUrl.name);
          })
        })
    })
  }

  // Function which uploads the actual photo to Firebase
  async upload(buffer, name)
  {
    let blob = new Blob([buffer], {type: "image/jpeg"});

    let storage = firebase.storage();

    storage.ref('ProfilePictures/' + name).put(blob).then((d) => {
      alert("Image Upload Done!");
    }).catch((error) => {
      alert(JSON.stringify(error))
    })
  
  }

```

It runs without error but the file doesn’t get uploaded to firebase storage… any suggestions?  
I generated my code by watching this tutorial…

Many thanks

---

<div class="post-metadata">

**Author:** ![bmcgowan94](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@bmcgowan94](https://forum.ionicframework.com/u/bmcgowan94)\
**Post date:** [April 25, 2018, 11:36am UTC](https://forum.ionicframework.com/t/ionic-file-chooser-with-upload-to-firebase-functionality/128682/2 "2018-04-25T11:36:50Z")

</div>

Can anyone help with this request?

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:38pm UTC](https://forum.ionicframework.com/t/ionic-file-chooser-with-upload-to-firebase-functionality/128682/3 "2021-07-19T21:38:51Z")

</div>

Closed on July 19, 2021, 9:38pm UTC


