0

I have application in Angular 9 and use DomSanitazer to build img url. I get error:

Not allowed to load local resource: file:///C:/MyApp/Images/uploads/fbf8152f-ccea-45a2-b9a9-150cd4c421a5/mmm_3424.png

In component.ts I have:

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

  public avatarSafeFileUrl: SafeResourceUrl;

and when I load img:

this.avatarSafeFileUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(this.myAvatar.filePath);

In html I have:

<img [src]="avatarSafeFileUrl"  />

And I get error like above.

Robert
  • 343
  • 1
  • 3
  • 14
  • 2
    Does this answer your question? [Why can't I do ?](https://stackoverflow.com/questions/4090712/why-cant-i-do-img-src-c-localfile-jpg) – cjd82187 Jul 31 '20 at 01:13
  • Ok, but I don't understand why I have to create browser extension? Where I should place img files to allowe them display in Angular? They have to be placed in assets? What in case when I need to store many gigabytes movies? – Robert Jul 31 '20 at 11:39
  • Browsers do not let you reference local files. You will need to have them hosted by your web server some how. – cjd82187 Jul 31 '20 at 11:43
  • Yes, you're right, I added staticFiles to Startup.cs and now it works – Robert Jul 31 '20 at 20:14

0 Answers0