How to open pdf file in local storage in Angular2 HTML5?

I am trying to open a .pdf file in local storage using iFrame. The code I tried looks like this.

In html file

<object [data]="sanitizer.bypassSecurityTrustResourceUrl(selectedItem.FilePath)" type="application/pdf">
<iframe [src]="sanitizer.bypassSecurityTrustResourceUrl(selectedItem.FilePath)">
</iframe>
</object>

in the Component.ts file

import { DomSanitizer } from '@angular/platform-browser';

   this.selectedItem.FilePath="D:\WorkDir\Exceline\US.Exceline.GMS\US.Common.Web.Web\DocumentStore\beta\1\145\pdf.pdf"

without a disinfectant, he issues an exception as follows.

ERROR Error: unsafe value used in a resource URL context (see 
http://g.co/ng/security#xss)
    at DomSanitizerImpl.webpackJsonp.../../../platform-
browser/@angular/platform-browser.es5.js.DomSanitizerImpl.sanitize 
(platform-browser.es5.js:3970)
    at setElementAttribute (core.es5.js:9320)
    at checkAndUpdateElementValue (core.es5.js:9291)
    at checkAndUpdateElementInline (core.es5.js:9238)
    at checkAndUpdateNodeInline (core.es5.js:12325)
    at checkAndUpdateNode (core.es5.js:12271)
    at debugCheckAndUpdateNode (core.es5.js:13132)
    at debugCheckRenderNodeFn (core.es5.js:13111)
    at Object.eval [as updateRenderer] (McDocumentsComponent.html:110)
    at Object.debugUpdateRenderer [as updateRenderer] (core.es5.js:13096)

With a disinfectant, it will not open the file. What am I doing wrong? How to open .pdf file on local server.

+4
source share
1 answer

The path seems to be wrong:

this.selectedItem.FilePath="D:\WorkDir\Exceline\US.Exceline.GMS\US.Common.Web.Web\DocumentStoreD:\WorkDir\Exceline\US.Exceline.GMS\US.Common.Web.Web\DocumentStore\beta\1\145\pdf.pdf"

Repeat part twice

D:\WorkDir\Exceline\US.Exceline.GMS\US.Common.Web.Web\DocumentStore
0
source

Source: https://habr.com/ru/post/1686179/


All Articles