Title: `LargeFileUploadTask.upload()` throws a 400 error when file size is smaller than max_chunk_size · Issue #718 · microsoftgraph/msgraph-sdk-python-core · GitHub
Open Graph Title: `LargeFileUploadTask.upload()` throws a 400 error when file size is smaller than max_chunk_size · Issue #718 · microsoftgraph/msgraph-sdk-python-core
X Title: `LargeFileUploadTask.upload()` throws a 400 error when file size is smaller than max_chunk_size · Issue #718 · microsoftgraph/msgraph-sdk-python-core
Description: Describe the bug While uploading a large file using LargeFileUploadTask to a SharePoint drive location, if the overall file size is less than the max_chunk_size defined (e.g uploading a 5 KB file but the chunk size is 10 MB), the async L...
Open Graph Description: Describe the bug While uploading a large file using LargeFileUploadTask to a SharePoint drive location, if the overall file size is less than the max_chunk_size defined (e.g uploading a 5 KB file b...
X Description: Describe the bug While uploading a large file using LargeFileUploadTask to a SharePoint drive location, if the overall file size is less than the max_chunk_size defined (e.g uploading a 5 KB file b...
Opengraph URL: https://github.com/microsoftgraph/msgraph-sdk-python-core/issues/718
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`LargeFileUploadTask.upload()` throws a 400 error when file size is smaller than max_chunk_size","articleBody":"### Describe the bug\r\n\r\nWhile uploading a large file using `LargeFileUploadTask` to a SharePoint drive location, if the overall file size is less than the max_chunk_size defined (e.g uploading a 5 KB file but the chunk size is 10 MB), the async `LargeFileUploadTask.upload()` method uploads the file but throws below error:\r\n\r\n```\r\nAPIError:\r\n APIError\r\n Code: 400\r\n message: The server returned an unexpected status code and no error class is registered for this code 400\r\n```\r\n\r\n### Expected behavior\r\n\r\nThe upload task should complete without any errors OR the error message should be meaningful e.g. File is too small.\r\n\r\n### How to reproduce\r\n\r\n```python\r\ndestination_path = \"path/to/your_file.txt\" # path on SharePoint drive where I want to upload the file\r\nfile_path = \"path/to/your_file.txt\" # A small file like 10 KB in my local system\r\n\r\nasync def upload_large_file(graph_client, drive_id):\r\n try:\r\n file = open(file_path, 'rb')\r\n uploadable_properties = DriveItemUploadableProperties(\r\n additional_data={'@microsoft.graph.conflictBehavior': 'replace'}\r\n )\r\n upload_session_request_body = CreateUploadSessionPostRequestBody(item=uploadable_properties)\r\n print(f\"Uploadable Properties: {uploadable_properties.additional_data}\")\r\n # can be used for normal drive uploads\r\n try:\r\n upload_session = await graph_client.drives.by_drive_id(\r\n drive_id\r\n ).items.by_drive_item_id(\"root:/my_docs/test_upload.txt:\"\r\n ).create_upload_session.post(upload_session_request_body)\r\n \r\n except APIError as ex:\r\n print(f\"Error creating upload session: {ex}\")\r\n\r\n # to be used for large file uploads\r\n large_file_upload_session = LargeFileUploadSession(\r\n upload_url=upload_session.upload_url,\r\n expiration_date_time=datetime.now() + timedelta(days=1),\r\n additional_data=upload_session.additional_data,\r\n is_cancelled=False,\r\n next_expected_ranges=upload_session.next_expected_ranges\r\n )\r\n\r\n max_chunk_size = 10 * 1024 * 1024\r\n task = LargeFileUploadTask(\r\n upload_session=large_file_upload_session, \r\n request_adapter=graph_client.request_adapter, \r\n stream=file, \r\n parsable_factory=DriveItem, \r\n max_chunk_size=max_chunk_size\r\n )\r\n total_length = os.path.getsize(file_path)\r\n \r\n # Upload the file\r\n # The callback\r\n def progress_callback(uploaded_byte_range: tuple[int, int]):\r\n print(f\"Uploaded {uploaded_byte_range[0]} bytes of {total_length} bytes\\n\\n\")\r\n\r\n try:\r\n upload_result = await task.upload(progress_callback)\r\n print(f\"Upload complete {upload_result}\")\r\n except APIError as ex:\r\n print(f\"Error uploading: {ex.message} - {ex.response_status_code}\")\r\n raise\r\n except APIError as e:\r\n print(f\"Error: {e}\")\r\n raise\r\n\r\nasyncio.run(upload_large_file(graph_client, drive_id))\r\n```\r\n\r\n### SDK Version\r\n\r\n1.1.7\r\n\r\n### Latest version known to work for scenario above?\r\n\r\n_No response_\r\n\r\n### Known Workarounds\r\n\r\nChanging the max_chunk_size value to (file_size - 1) seems to prevent the error from occurring.\r\n\r\n### Debug output\r\n\r\n\u003cdetails\u003e\u003csummary\u003eClick to expand log\u003c/summary\u003e\r\n```\r\n\r\n\u003cLog output here\u003e\r\n\r\n```\r\n\u003c/details\u003e\r\n\r\n\r\n### Configuration\r\n\r\nOS: Windows 10\r\nArchitecture: x64\r\nPython version: 3.9.19\r\n\r\n### Other information\r\n\r\n_No response_","author":{"url":"https://github.com/itsmariodias","@type":"Person","name":"itsmariodias"},"datePublished":"2024-11-23T07:31:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/718/msgraph-sdk-python-core/issues/718"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6ec604cf-3ea2-8331-ee26-6af48bece657 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C3BA:66035:C6662:10D577:6969D26B |
| html-safe-nonce | 004687f8a77b30f3ca29eb3f7643baf5268de25f51e00552706a4797a4e53eb4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0JBOjY2MDM1OkM2NjYyOjEwRDU3Nzo2OTY5RDI2QiIsInZpc2l0b3JfaWQiOiI3MjcyMDE2ODkxMDc5MTUyMjM1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 74668e0771d97e5b3f527c959e1a55e3854b25ee82430468e6298921f6a35f11 |
| hovercard-subject-tag | issue:2685595682 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoftgraph/msgraph-sdk-python-core/718/issue_layout |
| twitter:image | https://opengraph.githubassets.com/45f518317bfeb1fd0c8610ea80855e2c983825fa9b077128e926586c7273f5bd/microsoftgraph/msgraph-sdk-python-core/issues/718 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/45f518317bfeb1fd0c8610ea80855e2c983825fa9b077128e926586c7273f5bd/microsoftgraph/msgraph-sdk-python-core/issues/718 |
| og:image:alt | Describe the bug While uploading a large file using LargeFileUploadTask to a SharePoint drive location, if the overall file size is less than the max_chunk_size defined (e.g uploading a 5 KB file b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | itsmariodias |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoftgraph/msgraph-sdk-python-core git https://github.com/microsoftgraph/msgraph-sdk-python-core.git |
| octolytics-dimension-user_id | 17304259 |
| octolytics-dimension-user_login | microsoftgraph |
| octolytics-dimension-repository_id | 242847794 |
| octolytics-dimension-repository_nwo | microsoftgraph/msgraph-sdk-python-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 242847794 |
| octolytics-dimension-repository_network_root_nwo | microsoftgraph/msgraph-sdk-python-core |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width