在入口網站上設定檔案資料行

注意

自 2022 年 10 月 12 日起,Power Apps 入口網站為 Power Pages。 其他資訊:Microsoft Power Pages 現在已推出 (部落格)
我們很快就會遷移並將 Power Apps 入口網站文件與 Power Pages 文件併合。

檔案資料行可用來儲存二進位資料。 此資料行主要用於儲存單一檔案、附註或附件; 但是,也可以儲存其他形式的二進位資料。 您可以在基本表單與多步驟表單上設定檔案資料行,以提供上傳、查看、修改或刪除檔案的功能。 檔案資料行最多可以儲存 Microsoft Dataverse 資料表資料行中指定最大大小的檔案。

包含產品編號、產品名稱和產品目錄欄位的資料表動畫。要填入產品目錄欄位,使用者選取「選擇檔案」,然後瀏覽到要上傳並用於產品目錄的 PDF 檔案。

重要

  • 您無法使用基本表單或多步驟表單步驟上的插入模式來上傳檔案。

Liquid 程式碼

Liquid 是原生整合至 Microsoft Power Apps 入口網站中的開放原始碼範本語言。 開發人員在查詢資料時可以使用 fetchXML 和實體檢視表擷取檔案資料行值。

{% for item in tables.results.entities %}
    {{ item.columnname.Name }}
    {{ item.columnname.Size }}
    {{ item.columnname.Url }}
{% endfor %}
屬性 名描述
姓名 與資料行相關的檔案名稱
Size 檔案大小 (位元組)
URL 檔案下載 URL

範例:從連絡人資料表擷取檔案資料行資料

Dataverse 中為名稱為 myfileattribute 的連絡人資料表建立新的檔案資料類型資料行。

注意

請確認您已在連絡人資料表上設定適當的資料表權限,以讀取該記錄。

{% fetchxml contacts %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="contact">
    <attribute name="fullname" />
    <attribute name="myfileattribute" />    
  </entity>
</fetch>
{% endfetchxml %}

{% for item in contacts.results.entities %}
        "Full Name":"{{ item.fullname }}"
        "Entity File Url":"{{ item.myfileattribute.Name }}",      
        "Entity File Size":"{{ item.myfileattribute.Size }}",
        "Entity File Type":"{{ item.myfileattribute.Url }}" 
{% endfor %}

Web API

入口網站 Web API 可用於對 Dataverse 資料表中的檔案資料行執行建立、讀取、更新和刪除作業。

注意

確定您已針對要存取的資料表和檔案資料行設定了適當的 Web API 網站設定

擷取檔案資料

若要擷取檔案資料,請使用下列範例中所描述的 API 要求。

GET /_api/<entity-type>(id)/<file-attribute-name>/$value

從 Web 服務端點傳輸的檔案資料在單一服務呼叫中限制為最多 16 MB 的資料。 超過 16 MB 的檔案資料必須分成 4 MB 或較小的資料區塊。 每個區塊都會在不同的 API 呼叫中接收,直到所有檔案資料都已收到為止。 您有責任聯結已下載的資料區塊以形成完整的資料檔案,方法是將資料區塊以與接收區塊相同的順序來組合。

範例:檔案下載 < 16 MB

要求
HTTP
GET [Portal Url]/_api/accounts(62d53214-9dfa-eb11-94ee-0022482230a8)/myfileattribute/$value
Headers:
Content-Type: application/octet-stream
回應
204 No Content
Body:
Byte[ ]

範例:檔案下載 > 16 MB

要求
HTTP
GET [Portal Url]/_api/accounts(62d53214-9dfa-eb11-94ee-0022482230a8)/myfileattribute/$value
Headers:
Content-Type: application/octet-stream
Range: bytes=0-1023
回應
HTTP
204 No Content
Body:
Byte[ ]

上傳檔案資料

若要上傳檔案,請將檔案資料行的值設為包含檔案內容的位元組陣列。

PUT or PATCH /_api/<entity-type>(id)/<file-attribute-name>

範例:檔案上傳

Request
HTTP
PUT [Portal Url]/_api/accounts(62d53214-9dfa-eb11-94ee-0022482230a8)/myfileattribute
Headers:
Content-Type: application/octet-stream
Body :
Byte [ ]