# readAsArrayBuffer promise does not resolve

**URL:** <https://forum.ionicframework.com/t/readasarraybuffer-promise-does-not-resolve/195690>\
**Category:** Ionic Framework\
**Created:** [September 4, 2020, 1:58pm UTC](https://forum.ionicframework.com/t/readasarraybuffer-promise-does-not-resolve/195690 "2020-09-04T13:58:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aquinaswuwua](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@aquinaswuwua](https://forum.ionicframework.com/u/aquinaswuwua)\
**Post date:** [September 4, 2020, 1:58pm UTC](https://forum.ionicframework.com/t/readasarraybuffer-promise-does-not-resolve/195690/1 "2020-09-04T13:58:55Z")

</div>

Has anybody had the same problem? Promise does not resolve, how to get array buffer in a different way on android, any hints please? : ]

---

<div class="post-metadata">

**Author:** ![1antares1](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/1antares1/32/133884_2.png) [@1antares1](https://forum.ionicframework.com/u/1antares1)\
**Post date:** [September 5, 2020, 8:38pm UTC](https://forum.ionicframework.com/t/readasarraybuffer-promise-does-not-resolve/195690/2 "2020-09-05T20:38:01Z")

</div>

@aquinaswuwua Did you try making it asynchronous like this way? (remember the async in the method)  
`const result = await readAsArrayBufferPromise();`

–

And validate that it returns you exactly **readAsArrayBufferPromise();**

---

<div class="post-metadata">

**Author:** ![aquinaswuwua](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@aquinaswuwua](https://forum.ionicframework.com/u/aquinaswuwua)\
**Post date:** [September 7, 2020, 7:50am UTC](https://forum.ionicframework.com/t/readasarraybuffer-promise-does-not-resolve/195690/3 "2020-09-07T07:50:16Z")

</div>

Thank you for the answer! This is what I have for now:  
html file:

```auto
  <ion-button (click)="pickFile()">documents</ion-button>

```

page file:

```auto
  constructor(
    private file: File,
    private fileChooser: FileChooser,
    private filePath: FilePath,
    private fileOpener: FileOpener,
    private store: Store<fromDocuments.State>,
  ) {
  }

  pickFile() {
    this.fileChooser.open().then((fileuri) => {
      this.filePath.resolveNativePath(fileuri).then(resolvedNativePath => {
        this.file.resolveLocalFilesystemUrl(resolvedNativePath)
          .then((entry: FileEntry) => {
            (entry).file(file => this.readFile(entry));
          })
          .catch(err => {
          });

      });
    });
  }

  async readFile(file: FileEntry) {
    const path = file.nativeURL.substr(0, file.nativeURL.lastIndexOf('/') + 1);
    // testing if is possible to open a given file
    this.fileOpener.open(file.nativeURL, 'application/pdf')
      .then(() => alert('File is opened'))
      .catch(e => alert(`Error openening file ${JSON.stringify(e)}`));

    try {
      const buffer = await this.file.readAsArrayBuffer(path, file.name);
      alert('buffer');
      const fileBlob = new Blob([buffer], {type: 'application/pdf'});
    } catch (error) {
      alert(`Buffering failed ${JSON.stringify(error)}`)
    } finally {
      alert('finally');
    }
  }

```

despite that the fileOpener opens a file without any problems alert(‘buffer’) is never fired. Furthermore neither catch nor finally blocks are fired as well. I was using following tutorial:  
[https://devdactic.com/upload-ionic-files-firebase-storage/](https://devdactic.com/upload-ionic-files-firebase-storage/)  
any hints why it does not work?

---

<div class="post-metadata">

**Author:** ![1antares1](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/1antares1/32/133884_2.png) [@1antares1](https://forum.ionicframework.com/u/1antares1)\
**Post date:** [September 11, 2020, 9:53pm UTC](https://forum.ionicframework.com/t/readasarraybuffer-promise-does-not-resolve/195690/4 "2020-09-11T21:53:30Z")

</div>

@aquinaswuwua Why are you doing the **open();** synchronous before reading the buffer?

Notice the **.then();** it should also be an await:

```auto
this.fileOpener.open(file.nativeURL, 'application/pdf')
.then(() => alert('File is opened'))
.catch(e => alert(`Error openening file ${JSON.stringify(e)}`));

```

If not, comment on that extract and try again.

---

<div class="post-metadata">

**Author:** ![aquinaswuwua](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@aquinaswuwua](https://forum.ionicframework.com/u/aquinaswuwua)\
**Post date:** [September 12, 2020, 8:38pm UTC](https://forum.ionicframework.com/t/readasarraybuffer-promise-does-not-resolve/195690/5 "2020-09-12T20:38:21Z")

</div>

thank you for the answer! To be honest I was opening the file just to test whether path is correct etc. It works! The problem is with readAsArrayBuffer, even after commenting code you mentioned alert(‘buffer’) never fires which starts to drives me crazy 😉 next Friday I have a deadline for the project and I am completely stuck with the post method 😕 colleagues start to make fun at me 😉

---

<div class="post-metadata">

**Author:** ![1antares1](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/1antares1/32/133884_2.png) [@1antares1](https://forum.ionicframework.com/u/1antares1)\
**Post date:** [September 15, 2020, 5:59am UTC](https://forum.ionicframework.com/t/readasarraybuffer-promise-does-not-resolve/195690/6 "2020-09-15T05:59:12Z")

</div>

@aquinaswuwua Are you using Cordova or Capacitor as a base platform for you Ionic Project?

---

<div class="post-metadata">

**Author:** ![divya1993](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@divya1993](https://forum.ionicframework.com/u/divya1993)\
**Post date:** [October 26, 2022, 1:52pm UTC](https://forum.ionicframework.com/t/readasarraybuffer-promise-does-not-resolve/195690/7 "2022-10-26T13:52:09Z")

</div>

@1antares1 did you find any solution…? I’m facing the same issue with capacitor
