|
14 | 14 | from .data._odata import _ODataClient |
15 | 15 | from .operations.records import RecordOperations |
16 | 16 | from .operations.query import QueryOperations |
| 17 | +from .operations.files import FileOperations |
17 | 18 | from .operations.tables import TableOperations |
18 | 19 |
|
19 | 20 |
|
@@ -56,6 +57,7 @@ class DataverseClient: |
56 | 57 | - ``client.records`` -- create, update, delete, and get records (single or paginated queries) |
57 | 58 | - ``client.query`` -- query and search operations |
58 | 59 | - ``client.tables`` -- table and column metadata management |
| 60 | + - ``client.files`` -- file upload operations |
59 | 61 |
|
60 | 62 | Example: |
61 | 63 | Create a client and perform basic operations:: |
@@ -101,6 +103,7 @@ def __init__( |
101 | 103 | self.records = RecordOperations(self) |
102 | 104 | self.query = QueryOperations(self) |
103 | 105 | self.tables = TableOperations(self) |
| 106 | + self.files = FileOperations(self) |
104 | 107 |
|
105 | 108 | def _get_odata(self) -> _ODataClient: |
106 | 109 | """ |
@@ -665,67 +668,41 @@ def upload_file( |
665 | 668 | if_none_match: bool = True, |
666 | 669 | ) -> None: |
667 | 670 | """ |
| 671 | + .. note:: |
| 672 | + Deprecated. Use :meth:`~PowerPlatform.Dataverse.operations.files.FileOperations.upload` instead. |
| 673 | +
|
668 | 674 | Upload a file to a Dataverse file column. |
669 | 675 |
|
670 | | - :param table_schema_name: Schema name of the table, e.g. ``"account"`` or ``"new_MyTestTable"``. |
| 676 | + :param table_schema_name: Schema name of the table. |
671 | 677 | :type table_schema_name: :class:`str` |
672 | 678 | :param record_id: GUID of the target record. |
673 | 679 | :type record_id: :class:`str` |
674 | | - :param file_name_attribute: Schema name of the file column attribute (e.g., ``"new_Document"``). If the column doesn't exist, it will be created automatically. |
| 680 | + :param file_name_attribute: Schema name of the file column attribute. |
675 | 681 | :type file_name_attribute: :class:`str` |
676 | | - :param path: Local filesystem path to the file. The stored filename will be |
677 | | - the basename of this path. |
| 682 | + :param path: Local filesystem path to the file. |
678 | 683 | :type path: :class:`str` |
679 | 684 | :param mode: Upload strategy: ``"auto"`` (default), ``"small"``, or ``"chunk"``. |
680 | | - Auto mode selects small or chunked upload based on file size. |
681 | 685 | :type mode: :class:`str` or None |
682 | | - :param mime_type: Explicit MIME type to store with the file (e.g. ``"application/pdf"``). |
683 | | - If not provided, the MIME type may be inferred from the file extension. |
| 686 | + :param mime_type: Explicit MIME type to store with the file. |
684 | 687 | :type mime_type: :class:`str` or None |
685 | | - :param if_none_match: When True (default), sends ``If-None-Match: null`` header to only |
686 | | - succeed if the column is currently empty. Set False to always overwrite using |
687 | | - ``If-Match: *``. Used for small and chunk modes only. |
| 688 | + :param if_none_match: When True (default), only succeed if the column is |
| 689 | + currently empty. |
688 | 690 | :type if_none_match: :class:`bool` |
689 | | -
|
690 | | - :raises ~PowerPlatform.Dataverse.core.errors.HttpError: If the upload fails or the file column is not empty |
691 | | - when ``if_none_match=True``. |
692 | | - :raises FileNotFoundError: If the specified file path does not exist. |
693 | | -
|
694 | | - .. note:: |
695 | | - Large files are automatically chunked to avoid request size limits. The chunk mode performs multiple requests with resumable upload support. |
696 | | -
|
697 | | - Example: |
698 | | - Upload a PDF file:: |
699 | | -
|
700 | | - client.upload_file( |
701 | | - table_schema_name="account", |
702 | | - record_id=account_id, |
703 | | - file_name_attribute="new_Contract", |
704 | | - path="/path/to/contract.pdf", |
705 | | - mime_type="application/pdf" |
706 | | - ) |
707 | | -
|
708 | | - Upload with auto mode selection:: |
709 | | -
|
710 | | - client.upload_file( |
711 | | - table_schema_name="email", |
712 | | - record_id=email_id, |
713 | | - file_name_attribute="new_Attachment", |
714 | | - path="/path/to/large_file.zip", |
715 | | - mode="auto" |
716 | | - ) |
717 | 691 | """ |
718 | | - with self._scoped_odata() as od: |
719 | | - od._upload_file( |
720 | | - table_schema_name, |
721 | | - record_id, |
722 | | - file_name_attribute, |
723 | | - path, |
724 | | - mode=mode, |
725 | | - mime_type=mime_type, |
726 | | - if_none_match=if_none_match, |
727 | | - ) |
728 | | - return None |
| 692 | + warnings.warn( |
| 693 | + "client.upload_file() is deprecated. Use client.files.upload() instead.", |
| 694 | + DeprecationWarning, |
| 695 | + stacklevel=2, |
| 696 | + ) |
| 697 | + self.files.upload( |
| 698 | + table_schema_name, |
| 699 | + record_id, |
| 700 | + file_name_attribute, |
| 701 | + path, |
| 702 | + mode=mode, |
| 703 | + mime_type=mime_type, |
| 704 | + if_none_match=if_none_match, |
| 705 | + ) |
729 | 706 |
|
730 | 707 | # Cache utilities |
731 | 708 | def flush_cache(self, kind) -> int: |
|
0 commit comments