Skip to content

How to continue large file upload session upon failure #728

Open
@dcoghlan

Description

@dcoghlan

I'm currently using version 2.4.3 and having some issues why uploading large files.

The issue arises when I am using the proxy infrastructure on a customers network. I have to connect to proxy_1 which has an upstream proxy (proxy_2) that it forwards all its requests to. The same code works fine at other customer sites with a different proxy setup or when no proxy is used at all.

When executing the following

from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.files.file import File

ctx = ClientContext('https://my_full_url').with_client_credentials('my_client_id', 'my_secret_id')
local_path = 'test.zip'
remote_path_dir = 'Shared Documents/'
target_folder = ctx.web.ensure_folder_path(remote_path_dir.lstrip("/")).get().select(["ServerRelativePath"]).execute_query()
size_chunk = 4194304 # 4MB

with open(local_path, 'rb') as f:
    upload_session = target_folder.files.create_upload_session(f, size_chunk).execute_query_retry()

The upload session starts and more often or not, after a random amount of time, proxy_1 will have an issue connecting to proxy_2 and the upload session will fail with the following

OSError: HTTPSConnectionPool(host='acmecorp.sharepoint.com', port=443): Max retries exceeded with url: /teams/AcmeCorp/_api/Web/GetFileById('28ee7192-1234-5678-ac72-abc12345d5432')/continueUpload(uploadID='1a234b56-7c89-012d-b079-941145235067',fileOffset=218103808) (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 502 Bad Gateway',)))

i've tried execute_query(), execute_query_retry() and execute_query_with_incremental_retry() but all still fail with the same error. I've also tried various try/except blocks, however I've not figured out a way to be able to resume the current session from the current chunk.

Are there any tips or tricks I can use to handle this error and continue the upload session rather than it just erroring out?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions