`LargeFileUploadTask.upload()` throws a 400 error when file size is smaller than max_chunk_size
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Bắt đầu với LargeFileUploadTask.upload() và tái hiện trường hợp đã được báo cáo bằng một tệp nhỏ hơn max_chunk_size, chẳng hạn tệp 5 KB với kích thước chunk là 10 MB. Theo dõi kết quả upload và phản hồi 400 tiếp theo; được xem là hoàn tất khi quá trình upload tệp nhỏ hoàn tất mà không có lỗi ngoài dự kiến hoặc báo cáo một lỗi có ý nghĩa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 LargeFileUploadTask.upload() method uploads the file but throws below error:
APIError:
APIError
Code: 400
message: The server returned an unexpected status code and no error class is registered for this code 400
Expected behavior
The upload task should complete without any errors OR the error message should be meaningful e.g. File is too small.
How to reproduce
destination_path = "path/to/your_file.txt" # path on SharePoint drive where I want to upload the file
file_path = "path/to/your_file.txt" # A small file like 10 KB in my local system
async def upload_large_file(graph_client, drive_id):
try:
file = open(file_path, 'rb')
uploadable_properties = DriveItemUploadableProperties(
additional_data={'@microsoft.graph.conflictBehavior': 'replace'}
)
upload_session_request_body = CreateUploadSessionPostRequestBody(item=uploadable_properties)
print(f"Uploadable Properties: {uploadable_properties.additional_data}")
# can be used for normal drive uploads
try:
upload_session = await graph_client.drives.by_drive_id(
drive_id
).items.by_drive_item_id("root:/my_docs/test_upload.txt:"
).create_upload_session.post(upload_session_request_body)
except APIError as ex:
print(f"Error creating upload session: {ex}")
# to be used for large file uploads
large_file_upload_session = LargeFileUploadSession(
upload_url=upload_session.upload_url,
expiration_date_time=datetime.now() + timedelta(days=1),
additional_data=upload_session.additional_data,
is_cancelled=False,
next_expected_ranges=upload_session.next_expected_ranges
)
max_chunk_size = 10 * 1024 * 1024
task = LargeFileUploadTask(
upload_session=large_file_upload_session,
request_adapter=graph_client.request_adapter,
stream=file,
parsable_factory=DriveItem,
max_chunk_size=max_chunk_size
)
total_length = os.path.getsize(file_path)
# Upload the file
# The callback
def progress_callback(uploaded_byte_range: tuple[int, int]):
print(f"Uploaded {uploaded_byte_range[0]} bytes of {total_length} bytes\n\n")
try:
upload_result = await task.upload(progress_callback)
print(f"Upload complete {upload_result}")
except APIError as ex:
print(f"Error uploading: {ex.message} - {ex.response_status_code}")
raise
except APIError as e:
print(f"Error: {e}")
raise
asyncio.run(upload_large_file(graph_client, drive_id))
SDK Version
1.1.7
Latest version known to work for scenario above?
No response
Known Workarounds
Changing the max_chunk_size value to (file_size - 1) seems to prevent the error from occurring.
Debug output
Click to expand log
```</details>
### Configuration
OS: Windows 10
Architecture: x64
Python version: 3.9.19
### Other information
_No response_
- Ngôn ngữ chính
- Python
- Star
- 288
- Fork
- 53
- Merge trung bình
- 40 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoftgraph/msgraph-sdk-python-core
-
Logging to root loggerĐang mởstatus:waiting-for-triage type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoftgraph/msgraph-sdk-python-core#1078 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Missing 'deprecated' dependencyCó thể đã có người làm @Daiyuanranfeng đã nhận 3 ngày trước. Đang mởstatus:waiting-for-triage type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
microsoftgraph/msgraph-sdk-python-core#1030 · 4 bình luận · 4 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Replace httpx with httpx2Đang mởstatus:waiting-for-triage type:feature
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
microsoftgraph/msgraph-sdk-python-core#1115 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
BatchRequestItem loses query parameters from RequestInformationCó thể đã có người làm @Daiyuanranfeng đã nhận 3 ngày trước. Đang mởstatus:waiting-for-triage type:bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
microsoftgraph/msgraph-sdk-python-core#1035 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status:waiting-for-triage
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
microsoftgraph/msgraph-sdk-python-core#935 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoftgraph/msgraph-sdk-python-core
Issue tương tự
-
tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Plugin] 群聊记忆 · 人格养成Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 74/100
-
bug maintainer-managed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
awslabs/visual-asset-management-system#1759 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100