gpt4 book ai didi

Base64 图像的 Angular2 net::ERR_UNKNOWN_URL_SCHEME

转载 作者:太空狗 更新时间:2023-10-29 19:35:06 28 4
gpt4 key购买 nike

我正在尝试在 HTML 上显示 jpg/png 图像。从服务器我得到 Base64 字符串。我在 HTML 中显示为:

<md-card>
<md-card-content>
<img id="uploadPicture" class="uploadPicture" [src]="'data:image/jpg;base64,' +file_src ">
</md-card-content>
<md-card-actions>
<input id="uploadedFile" type="file" #fileInput (change)="chooseImage(fileInput.files)"/>
<button md-raised-button color="primary" [disabled]="isUploaded" (click)="uploadPicture(fileInput.files)">{{'upload picture' | translate}}</button>
<button md-raised-button color="primary" [disabled]="isRemoved" (click)="removePicture()">{{'remove picture' | translate}}</button>
</md-card-actions>
</md-card>

当我使用 PUT URL 上传图片时,它工作正常。但是当我尝试使用 GET API 下载它时,它给我的错误是:

net::ERR_UNKNOWN_URL_SCHEME

我也收到警告:

WARNING: sanitizing unsafe URL value

我在我的组件中使用 sanitizer 如下:

ngOnInit(): void {
if(this.file_src!='')
{
this.userService.getPicture()
.then(
(response:any) => {
console.log(response);
this.file_src = response.json();
this.file_src = this._sanitizer.sanitize(SecurityContext.URL, `data:image/png;base64,${this.file_src}`);
}
)
.catch(
(error:any) => {
this.displayError();
}
)
}
}

但是没有用。谁能告诉我可能是什么问题?

最佳答案

上传图片时在base64string中附加http:\或https:\。

关于Base64 图像的 Angular2 net::ERR_UNKNOWN_URL_SCHEME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40808121/

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