Call onedrive API to Upload a file with an unknown total size, but specify its total size as a fixed value.

d d 80 Reputation points
2024-12-18T03:33:23.3733333+00:00

The total file size is between 500KB and 1024MB, but the actual total file size is not known before uploading.

Can I specify the total file size as 1024MB (not the actual total file size) before uploading and manually finish the upload session, will the server responds to the final request with an HTTP 201 Created or HTTP 200 OK and reflect the actual total size uploaded?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,657 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,221 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,650 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 43,801 Reputation points
    2024-12-18T08:52:30.21+00:00

    Hi @d d

    No.

    When using the OneDrive API to upload a file, if you don't know the actual total file size beforehand, you cannot arbitrarily specify a fixed value (like 1024MB). The OneDrive API requires that you specify the accurate file size in the Content-Range header when uploading a file. If the specified file size does not match the actual uploaded file size, the request will fail.

    User's image

    Therefore, you cannot specify the total file size as 1024MB before uploading and expect the server to accept and reflect the actual uploaded size. You need to ensure that the file size specified in each request is accurate.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.