gpt4 book ai didi

node.js - Angular 5 net::ERR_UNKNOWN_URL_SCHEME 用于来自 express 服务器的图像

转载 作者:太空狗 更新时间:2023-10-29 18:07:48 24 4
gpt4 key购买 nike

我在显示来 self 的 node.js(快速服务器)localhost:3000/assets/images/uploads 的图像时遇到了一些问题。当我在浏览器中输入此 URL 时效果很好,浏览器显示图像但是当我将其分配给 Angular 5 应用程序中的变量并使用绑定(bind)到 时,我得到

Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME.

我附上下面的代码。请审核。

export class ProfileComponent implements OnInit {

user: any;
url: "";
path: SafeUrl;
public uploader:FileUploader = new FileUploader({url: URL, itemAlias: 'photo'});

constructor(private authService: AuthServiceService,
private userService: UsersService,
private http: Http,
private el: ElementRef,
private _DomSanitizationService: DomSanitizer) {





}


ngOnInit() {
this.user = this.authService.user;
console.log(this.user);
this.path = this._DomSanitizationService.bypassSecurityTrustUrl(this.user.img);
<input type="file" name="photo" ng2FileSelect [uploader]="uploader" />
<!-- button to trigger the file upload when submitted -->
<button type="button" class="btn btn-success btn-s" (click)="uploader.uploadAll()" [disabled]="!uploader.getNotUploadedItems().length">
Upload with ng-2 file uploader
</button>


<div class="user profile">
<div class="ui container">
<div class="ui grid">
<div class="ui five wide column">
<div class="ui card">

<a class="image poping up" href="" id="profile-avatar" data-content="avatar" data-variation="inverted tiny" data-position="bottom center">
<img [src] = "path" target="_blank" title="Hamza"/>
</a>

<div class="content">
<span class="header text center">Hamza</span>
<span class="username text center">Hamza</span>
</div>
<div class="extra content">
<ul class="text black">

<li><i class="octicon octicon-location"></i> Lahore</li>


<li>
<i class="octicon octicon-mail"></i>
<a href="" rel="nofollow">email</a>
</li>


<li><i class="octicon octicon-clock"></i> date</li>



</ul>
</div>
</div>
</div>
<div class="ui eleven wide column">
<div class="ui secondary pointing menu">
<a class="activity">
<i class="octicon octicon-repo"></i> Posts
</a>
<a class="item">
<a class="activity">
<i class="octicon octicon-rss"></i> Top Posts
</a>
</a>
</div>

</div>
</div>
</div>
</div>

最佳答案

解决方案!

对于遇到此问题的任何人,请确保您在图像源属性中提供的地址附加有“http://”,因为在我的情况下我没有附加它。这为我解决了问题,现在它就像一个魅力!

你的 url 必须有点像这样:“http://localhost:3000/assets/images/uploads/c91a3649fc432040e54b9179a72539ad1530343409773.png

令人困惑的部分实际上是当你在浏览器的 url 中写入它时,没有 http://,它会自动附加它而不让我们知道,但这不是与 Angular 不同,您必须显式地编写它。快乐编码。我希望这对某人有所帮助,因为我花了 14 个小时才弄明白。

关于node.js - Angular 5 net::ERR_UNKNOWN_URL_SCHEME 用于来自 express 服务器的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51112880/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com