FileOperations 类
文件操作的命名空间。
通过 . 访问 。client.files 为 Dataverse 文件列提供文件上传操作。
例:
client = DataverseClient(base_url, credential)
client.files.upload(
"account", account_id, "new_Document", "/path/to/file.pdf"
)
方法
| 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
必需
|
表的架构名称(例如 |
|
record_id
必需
|
目标记录的 GUID。 |
|
file_column
必需
|
文件列属性(例如, |
|
path
必需
|
文件的本地文件系统路径。 存储的文件名将是此路径的基名称。 |
|
mode
必需
|
上传策略: |
|
mime_type
必需
|
要随文件一起存储的显式 MIME 类型(例如 |
|
if_none_match
必需
|
如果为 True(默认值),则仅当列当前为空时,才会将标头发送到 |
仅限关键字的参数
| 名称 | 说明 |
|---|---|
|
mode
|
默认值: None
|
|
mime_type
|
默认值: None
|
|
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",
)