ng2-pdf-viewer icon indicating copy to clipboard operation
ng2-pdf-viewer copied to clipboard

403 when rendering the pdf, even if file is already stored in memory.

Open Gertjan-Goetynck opened this issue 2 years ago • 1 comments

Bug Report or Feature Request (mark with an x)
- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [x] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request

Hey!

I'm trying to use ng2 pdf viewer to render a pdf blob that is already saved in memory, but I keep getting a 403 error when trying to render the pdf despite the file being available in memory in a variable (I also have a download button that uses the same variable to download the file locally and that works fine).

This error only happens on our development server. When running my application on localhost everyone is working perfectly fine.

After doing some testing, I seem to have discovered that the pdf viewer module does another backend call to render the PDF, despite the fact that I refer to a variable that holds the file, and this second call is what causes the 403 error. Is this possible?

The chain of events seems to be:

  • My pdf gets loaded through a call to the backend, in the subscribe I put the pdf blob in a file variable
  • the pdf-viewer component is rendered visible since the ng-if is set to true
  • A second call seems to happen to my backend despite the HTML src property referring through an in memory blob. Is this normal behavior or am I minsterpreting what is happening? Can this be avoided? I'm pretty sure this is what is causing my issue.

My typescript method is the following:

downloadFile(observable: Observable<any>) { observable.subscribe((document: any) => { console.log(document) this.file = document; console.log(this.file) if (!this.isFilePdF()) { this.isLoading = false; } }) }

And my HTML is:

<pdf-viewer (error)="logError($event)" [zoom]="zoomRatio" [hidden]="isLoading" *ngIf="isFilePdF()" (after-load-complete)="finishLoading($event)" [(page)]="currentPage" [src]="file" [original-size]="false" [class.height]="!isLoading" style=" width: 100%; background-color:whitesmoke"> </pdf-viewer>

A screenshot of my network tab with the error:

ng2PDfViewerError

As you see, the first download downloads the file perfectly fine and saves it in the parameter. The second download is causing the error, and I have no idea why the second download is happening since I didn't do anything in my code for it.

If there is a way to just use the blob variable from the first download, and not having the second one happen, I'm sure my issue would be resolved.

Does anyone know how to fix the issue I am having?

Gertjan-Goetynck avatar Jun 02 '22 07:06 Gertjan-Goetynck

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 10 '22 04:08 stale[bot]