在门户上配置文件列
备注
从 2022 年 10 月 12 日起,Power Apps 门户更名为 Power Pages。 详细信息请参阅:Microsoft Power Pages 现已正式发布(博客)
不久后我们将迁移 Power Apps 门户文档并将其与 Power Pages 文档合并在一起。
文件列用于存储二进制数据。 此列主要用于存储单个文件、注释或附件;但可以存储其他形式的二进制数据。 您可以在基本窗体和多步窗体上配置文件列,以提供上传、查看、修改或删除文件的功能。 文件列最大可以存储为 Microsoft Dataverse 表列指定的最大大小的文件。
重要
- 您无法在基本窗体或多步窗体步骤中使用插入模式上传文件。
Liquid 代码
Liquid 是 Microsoft Power Apps 门户本地集成的开源模板语言。 开发人员在查询数据时可以使用 fetchXML 和实体视图检索文件列值。
{% for item in tables.results.entities %}
{{ item.columnname.Name }}
{{ item.columnname.Size }}
{{ item.columnname.Url }}
{% endfor %}
属性 | 说明 |
---|---|
Name | 与列关联的文件的名称 |
规模 | 文件大小(以字节为单位) |
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 [ ]