在入口網站上設定影像資料行
注意
自 2022 年 10 月 12 日起,Power Apps 入口網站為 Power Pages。 其他資訊:Microsoft Power Pages 現在已推出 (部落格)
我們很快就會遷移並將 Power Apps 入口網站文件與 Power Pages 文件併合。
影像資料行會在 Dataverse 資料表的資料行中儲存影像檔案。 將影像資料行新增至表單,以上傳、查看、修改及刪除影像。 表單會顯示影像的縮圖 (如果有的話)。
注意
您無法使用基本表單或多步驟表單步驟上的插入模式來上傳影像檔案。
Image URL
影像 URL 表示影像儲存位置的完整 URL。 這可以用來進行開發和疑難排解。
影像 URL 採用下列形式:
{0}/Image/download.aspx?entity={1}&attribute={2}&id={3}
其中:
{0} 是入口網站 URL
{1} 是實體的邏輯名稱
{2} 是資料行的邏輯名稱
{3} 是影像識別碼
例如,如果您的入口網站位於 https://contososite.powerappsportals.com,程式碼看起來就像這樣:
https://contososite.powerappsportals.com/Image/download.aspx?entity=contact&attribute=entityimage&id=cb059a4a-b1a6-ec11-9840-00224829604e
Liquid
您可以使用 Liquid 程式碼從 Dataverse 資料表擷取記錄來設計網站。 使用 fetchXML 和實體檢視表來擷取影像資料行值,如下所示:
{% for item in tables.results.entities %}
{{ item.columnname.Type }}
{{ item.columnname.Size }}
{{ item.columnname.Url }}
{{ item.columnname.Value }}
{% endfor %}
其中:
類型為影像的 mime 類型
大小為影像的大小 (以位元組為單位)
值為 base64 字串的影像值
URL 為影像 URL
範例:擷取預設連絡人影像
{% fetchxml contacts %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="contact">
<attribute name="fullname"/>
<attribute name="entityimage"/>
</entity>
</fetch>
{% endfetchxml %}
{% for item in contacts.results.entities %}
{
"Full Name":"{{ item.fullname }}"
"Entity Image Type":"{{ item.entityimage.Type}}",
"Entity Image Size":"{{ item.entityimage.Size}}",
"Entity Image Url":"{{ item.entityimage.Url}}",
"Entity Image Value":"{{ item.entityimage.Value}}"
}
{% endfor %}
Web API
入口網站 Web API 可用於對 Dataverse 資料表中的影像資料行建立、讀取、更新和刪除影像。
擷取影像資料
若要下載縮圖影像資料,請使用下列 API 呼叫:
GET /_api/<entity-type>(id)/<image-attribute-name>/$value
從 Web 服務端點傳輸的影像資料在單一服務呼叫中限制為最多 16 MB。
範例:下載縮圖
在以下範例中,我們將使用 GET 呼叫來下載縮圖 (如果有的話)。
HTTP 要求:
GET [Portal Url]/_api/accounts(62d53214-9dfa-eb11-94ee-0022482230a8)/entityimage/$value
Headers:
Content-Type: application/octet-stream
HTTP 回應:
204 No Content
Body:
Byte[ ]
在此範例中不存在縮圖,因此不會傳回任何影像。 如果存在縮圖,回覆會傳回具有值的位元組陣列。
上傳影像資料
若要上傳影像,請將影像資料行的值設為包含影像檔案內容的位元組陣列:
PUT or PATCH /_api<entity-type>(id)/<image-attribute-name>
範例:上傳影像
HTTP 要求:
PUT [Portal Url]/_api/accounts(62d53214-9dfa-eb11-94ee-0022482230a8)/entityimage
Headers:
Content-Type: application/octet-stream
Body :
Byte [ ]
上傳設定檔影像
已驗證的入口網站使用者可以在入口網站的設定檔區段上傳其圖片。 該影像會儲存在 Dataverse 的相應連絡人記錄的實體影像資料行中。 使用者最多可以上傳 10 MB 的影像。
建立網站設定
首先,您必須建立網站設定,以允許經驗證的使用者上傳設定檔圖片:
登入 Power Apps。
選取包含您入口網站的環境。
在左窗格選取應用程式,然後開啟入口網站管理應用程式。
在左窗格中,選取網站設定。
建立名為 Profile/ShowImage 的設定,並將其值設定為 True。 (如果該設定已存在,請將其值設為 True。)
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應