Skip to content

Commit 515cf52

Browse files
zhaodongwang-msftMax Wang
andauthored
Users/zhaodongwang/upload feature (#17)
* add upload feature * consolidate to one upload_file method * updated comment about upload method * updates per comments * minor format fixes --------- Co-authored-by: Max Wang <zhaodongwang@microsoft.com>
1 parent 8fcba62 commit 515cf52

5 files changed

Lines changed: 717 additions & 1 deletion

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A minimal Python SDK to use Microsoft Dataverse as a database for Azure AI Found
77
- Bulk create — Pass a list of records to `create(...)` to invoke the bound `CreateMultiple` action; returns `list[str]` of GUIDs. If any payload omits `@odata.type` the SDK resolves and stamps it (cached).
88
- Bulk update — Provide a list of IDs with a single patch (broadcast) or a list of per‑record patches to `update(...)`; internally uses the bound `UpdateMultiple` action; returns nothing. Each record must include the primary key attribute when sent to UpdateMultiple.
99
- Retrieve multiple (paging) — Generator-based `get_multiple(...)` that yields pages, supports `$top` and Prefer: `odata.maxpagesize` (`page_size`).
10+
- Upload files — Call `upload_file(entity_set, ...)` and a upload method will be auto picked (user can also overwrite the upload mode). See https://learn.microsoft.com/en-us/power-apps/developer/data-platform/file-column-data?tabs=sdk#upload-files
1011
- Metadata helpers — Create/inspect/delete simple custom tables (EntityDefinitions + Attributes).
1112
- Pandas helpers — Convenience DataFrame oriented wrappers for quick prototyping/notebooks.
1213
- Auth — Azure Identity (`TokenCredential`) injection.
@@ -19,6 +20,7 @@ A minimal Python SDK to use Microsoft Dataverse as a database for Azure AI Found
1920
- Bulk create via `CreateMultiple` (collection-bound) by passing `list[dict]` to `create(entity_set, payloads)`; returns list of created IDs.
2021
- Bulk update via `UpdateMultiple` (invoked internally) by calling unified `update(entity_set, ids, patch|patches)`; returns nothing.
2122
- Retrieve multiple with server-driven paging: `get_multiple(...)` yields lists (pages) following `@odata.nextLink`. Control total via `$top` and per-page via `page_size` (Prefer: `odata.maxpagesize`).
23+
- Upload files, using either a single request (supports file size up to 128 MB) or chunk upload under the hood
2224
- Optional pandas integration (`PandasODataClient`) for DataFrame based create / get / query.
2325

2426
Auth:
@@ -103,6 +105,8 @@ The quickstart demonstrates:
103105
- Retrieve multiple with paging (`$top` vs `page_size`)
104106
- Executing a read-only SQL query (Web API `?sql=`)
105107

108+
For upload files functionalities, run quickstart_file_upload.py instead
109+
106110
## Examples
107111

108112
### DataverseClient (recommended)
@@ -196,6 +200,19 @@ Bulk create notes:
196200
- Single-record `create` returns a one-element list of GUIDs.
197201
- Metadata lookup for `@odata.type` is performed once per entity set (cached in-memory).
198202

203+
## File upload
204+
205+
```python
206+
client.upload_file('account', record_id, 'sample_filecolumn', 'test.pdf')
207+
208+
client.upload_file('account', record_id, 'sample_filecolumn', 'test.pdf', mode='chunk', if_none_match=True)
209+
210+
```
211+
212+
Notes:
213+
- upload_file picks one of the three methods to use based on file size: if file is less than 128 MB uses upload_file_small, otherwise uses upload_file_chunk
214+
- upload_file_small makes a single Web API call and only supports file size < 128 MB
215+
- upload_file_chunk uses PATCH with Content-Range to upload the file (more aligned with HTTP standard compared to Dataverse messages). It consists of 2 stages 1. PATCH request to get the headers used for actual upload. 2. Actual upload in chunks. It uses x-ms-chunk-size returned in the first stage to determine chunk size (normally 4 MB), and use Content-Range and Content-Length as metadata for the upload. Total number of Web API calls is number of chunks + 1
199216

200217
## Retrieve multiple with paging
201218

0 commit comments

Comments
 (0)