FileOperations 类

文件操作的命名空间。

通过 . 访问 。client.files 为 Dataverse 文件列提供文件上传操作。

例:


   client = DataverseClient(base_url, credential)

   client.files.upload(
       "account", account_id, "new_Document", "/path/to/file.pdf"
   )

构造函数

FileOperations(client: DataverseClient)

参数

名称 说明
client
必需

DataverseClient 实例。

方法

upload

将文件上传到 Dataverse 文件列。

upload

将文件上传到 Dataverse 文件列。

upload(table: str, record_id: str, file_column: str, path: str, *, mode: str | None = None, mime_type: str | None = None, if_none_match: bool = True) -> None

参数

名称 说明
table
必需
str

表的架构名称(例如 "account""new_MyTestTable")。

record_id
必需
str

目标记录的 GUID。

file_column
必需
str

文件列属性(例如, "new_Document")的架构名称。 如果该列不存在,将自动创建该列。

path
必需
str

文件的本地文件系统路径。 存储的文件名将是此路径的基名称。

mode
必需
str

上传策略: "auto" (默认), "small""chunk"。 自动模式根据文件大小选择小型或分块上传。

mime_type
必需
str

要随文件一起存储的显式 MIME 类型(例如 "application/pdf")。 如果未提供,则默认为 "application/octet-stream".

if_none_match
必需

如果为 True(默认值),则仅当列当前为空时,才会将标头发送到 If-None-Match: null 成功。 将 False 设置为始终使用 If-Match: *

仅限关键字的参数

名称 说明
mode
默认值: None
mime_type
默认值: None
if_none_match
默认值: True

例外

类型 说明

如果上传失败或文件列在以下情况下不为空 if_none_match=True

如果指定的文件路径不存在。

示例

上传 PDF 文件:


   client.files.upload(
       "account",
       account_id,
       "new_Contract",
       "/path/to/contract.pdf",
       mime_type="application/pdf",
   )

使用自动模式选择进行上传:


   client.files.upload(
       "email",
       email_id,
       "new_Attachment",
       "/path/to/large_file.zip",
   )