[英]how to receive the response of coming from the API specified with the url attribute of p-fileUpload?
[英]How can i display image in P-fileupload primeng programatically?
我正在使用primeng p-fileupload
上傳圖片,但我想以編程方式預覽圖片 onUpload 事件,上傳后我得到的圖片路徑為 URL
blob:https://primeng-breadcrumb-demo-ntijjo.stackblitz.io/1c2dadec-e61b-42b7-8c6b-c56d342fb136
,但圖像未顯示...因此在檢查圖像后顯示
unsafe:blob:https://primeng-breadcrumb-demo-ntijjo.stackblitz.io/6a7a24d7-33fc-4738-b7f8-93b4b6007123
我附上堆棧閃電戰 URL 以供參考:- https://stackblitz.com/edit/primeng-breadcrumb-demo-ntijjo?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts
請幫我解決這些問題。
提前致謝。
您可以使用 FileReader API 讀取文件的內容,然后將其設置為 src。
例如:
onUpload(e## Heading ##vent) {
const reader = new FileReader();
reader.onload = (e: any) => {
// Set image src
this.imageSrc = e.target.result;
}
reader.readAsDataURL(event.files[0]);
}
然后在你的模板中:
<img [src]="imageSrc" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.