sarriaroman / photoviewer

PhotoViewer Cordova Plugin
MIT License
157 stars 216 forks source link

[QUESTION] Headers as PhotoViewerOptions on Ionic 3 #182

Open caike08 opened 5 years ago

caike08 commented 5 years ago

Hello, guys!

The application I'm currently working needs to access a private URL to see the image. As far as I could read in photo viewer's documentation, there's a key called headers where I should add all headers parameters.

The problem is, it seems it doesn't work on Ionic 3. While I was debugging, I could find the following code snippet:

export interface PhotoViewerOptions { share?: boolean; }

1) Isn't headers expected to be declared within PowerViewerOptions? 2) In case headers is not recognized as a valid key on the Ionic Plugin, how could I access a private URL link then?

Here is what I've done so far:

 async viewEvidence(file: any) {
    if (file.uri.includes('https:')) {
      const options = await this.getImageViewerOptions();

      this.photoViewer.show(file.uri, file.fileName, options);
    } else  {
      this.photoViewer.show(file.uri, file.fileName, { share: false });
    }
  }

  private getImageViewerOptions(): Promise<any> {
    return this.storageService.get('access_token').then(token => {
      const options = {
        share: false,
        headers: `{Authorization: Bearer ${token}}`
      };

      return Promise.resolve(options);
    });
  }

Thanks!