|
12 | 12 |
|
13 | 13 | from box_sdk_gen.networking.fetch_options import ResponseFormat |
14 | 14 |
|
| 15 | +from box_sdk_gen.schemas.upload_part_plan import UploadPartPlan |
| 16 | + |
15 | 17 | from box_sdk_gen.internal.utils import Buffer |
16 | 18 |
|
17 | 19 | from box_sdk_gen.internal.utils import HashName |
|
26 | 28 |
|
27 | 29 | from box_sdk_gen.schemas.upload_parts import UploadParts |
28 | 30 |
|
| 31 | +from box_sdk_gen.schemas.upload_session_plan_response import UploadSessionPlanResponse |
| 32 | + |
| 33 | +from box_sdk_gen.schemas.upload_session_plan_request import UploadSessionPlanRequest |
| 34 | + |
29 | 35 | from box_sdk_gen.schemas.files import Files |
30 | 36 |
|
31 | 37 | from box_sdk_gen.schemas.upload_part import UploadPart |
@@ -617,6 +623,112 @@ def get_file_upload_session_parts( |
617 | 623 | ) |
618 | 624 | return deserialize(response.data, UploadParts) |
619 | 625 |
|
| 626 | + def create_file_upload_session_plan_by_url( |
| 627 | + self, |
| 628 | + url: str, |
| 629 | + parts: List[UploadPartPlan], |
| 630 | + *, |
| 631 | + extra_headers: Optional[Dict[str, Optional[str]]] = None |
| 632 | + ) -> UploadSessionPlanResponse: |
| 633 | + """ |
| 634 | + Using this method with urls provided in response when creating a new upload session is preferred to use over CreateFileUploadSessionPlan method. |
| 635 | +
|
| 636 | + This allows to always upload your content to the closest Box data center and can significantly improve upload speed. |
| 637 | +
|
| 638 | +
|
| 639 | + Plan an upload session by checking which parts already exist on the server. |
| 640 | +
|
| 641 | +
|
| 642 | + This endpoint allows clients to optimize uploads by skipping parts that |
| 643 | +
|
| 644 | +
|
| 645 | + have already been uploaded (cache hits) and only uploading missing parts. |
| 646 | +
|
| 647 | +
|
| 648 | + The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions) |
| 649 | +
|
| 650 | +
|
| 651 | + and [`Get upload session`](e://get-files-upload-sessions-id) endpoints. |
| 652 | +
|
| 653 | + :param url: URL of createFileUploadSessionPlan method |
| 654 | + :type url: str |
| 655 | + :param parts: The list of parts to check for existence. |
| 656 | + :type parts: List[UploadPartPlan] |
| 657 | + :param extra_headers: Extra headers that will be included in the HTTP request., defaults to None |
| 658 | + :type extra_headers: Optional[Dict[str, Optional[str]]], optional |
| 659 | + """ |
| 660 | + if extra_headers is None: |
| 661 | + extra_headers = {} |
| 662 | + request_body: Dict = {'parts': parts} |
| 663 | + headers_map: Dict[str, str] = prepare_params({**extra_headers}) |
| 664 | + response: FetchResponse = self.network_session.network_client.fetch( |
| 665 | + FetchOptions( |
| 666 | + url=url, |
| 667 | + method='POST', |
| 668 | + headers=headers_map, |
| 669 | + data=serialize(request_body), |
| 670 | + content_type='application/json', |
| 671 | + response_format=ResponseFormat.JSON, |
| 672 | + auth=self.auth, |
| 673 | + network_session=self.network_session, |
| 674 | + ) |
| 675 | + ) |
| 676 | + return deserialize(response.data, UploadSessionPlanResponse) |
| 677 | + |
| 678 | + def create_file_upload_session_plan( |
| 679 | + self, |
| 680 | + upload_session_id: str, |
| 681 | + parts: List[UploadPartPlan], |
| 682 | + *, |
| 683 | + extra_headers: Optional[Dict[str, Optional[str]]] = None |
| 684 | + ) -> UploadSessionPlanResponse: |
| 685 | + """ |
| 686 | + Plan an upload session by checking which parts already exist on the server. |
| 687 | +
|
| 688 | + This endpoint allows clients to optimize uploads by skipping parts that |
| 689 | +
|
| 690 | +
|
| 691 | + have already been uploaded (cache hits) and only uploading missing parts. |
| 692 | +
|
| 693 | +
|
| 694 | + The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions) |
| 695 | +
|
| 696 | +
|
| 697 | + and [`Get upload session`](e://get-files-upload-sessions-id) endpoints. |
| 698 | +
|
| 699 | + :param upload_session_id: The ID of the upload session. |
| 700 | + Example: "D5E3F7A" |
| 701 | + :type upload_session_id: str |
| 702 | + :param parts: The list of parts to check for existence. |
| 703 | + :type parts: List[UploadPartPlan] |
| 704 | + :param extra_headers: Extra headers that will be included in the HTTP request., defaults to None |
| 705 | + :type extra_headers: Optional[Dict[str, Optional[str]]], optional |
| 706 | + """ |
| 707 | + if extra_headers is None: |
| 708 | + extra_headers = {} |
| 709 | + request_body: Dict = {'parts': parts} |
| 710 | + headers_map: Dict[str, str] = prepare_params({**extra_headers}) |
| 711 | + response: FetchResponse = self.network_session.network_client.fetch( |
| 712 | + FetchOptions( |
| 713 | + url=''.join( |
| 714 | + [ |
| 715 | + self.network_session.base_urls.upload_url, |
| 716 | + '/2.0/files/upload_sessions/', |
| 717 | + to_string(upload_session_id), |
| 718 | + '/plan', |
| 719 | + ] |
| 720 | + ), |
| 721 | + method='POST', |
| 722 | + headers=headers_map, |
| 723 | + data=serialize(request_body), |
| 724 | + content_type='application/json', |
| 725 | + response_format=ResponseFormat.JSON, |
| 726 | + auth=self.auth, |
| 727 | + network_session=self.network_session, |
| 728 | + ) |
| 729 | + ) |
| 730 | + return deserialize(response.data, UploadSessionPlanResponse) |
| 731 | + |
620 | 732 | def create_file_upload_session_commit_by_url( |
621 | 733 | self, |
622 | 734 | url: str, |
|
0 commit comments