can we used more than 4MB file upload using Graph API

Amar Dobliyal 0 Reputation points
2023-01-20T09:19:04.0733333+00:00

Method: PUT
URL: https://graph.microsoft.com/v1.0/me/drive/items/fileName.jpeg/content
can we send more than 4MB file using the above API call
because using the above API we can able to send 100MB file in Microsoft oneDrive so can you confirm if it will be used to send more than 4MB file?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,978 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Siddharth Gautam 860 Reputation points
    2023-01-20T12:37:20.6066667+00:00

    Hello Amar Dobliyal,

    Thanks for posting!

    As per the Microsoft Graph Documentation, Using Graph Endpoint PUT https://graph.microsoft.com/v1.0/me/drive/items/fileName.jpeg/content, only support uploading of files up to 4MB in size. The simple upload API allows you to provide the contents of a new file or update the contents of an existing file in a single API call.

    For uploading the files more than 4MB, we need to use upload session resource, please follow the below steps.

    1. While Using Graph Endpoint POST /me/drive/items/{itemId}:/{fileName}:/createUploadSession, in response we will get uploadUrl. pic1st
    2. To upload the file, or a portion of the file, your app makes a PUT request to the uploadUrl value received in the createUploadSession response. You can upload the entire file, or split the file into multiple byte ranges, as long as the maximum bytes in any given request is less than 60 MiB. 2nd
    3. Authorization request header should be No Auth. The PUT query uses a pre-authenticated URL from the uploadUrl property.
    4. We need to select our file in binary option inside body.
    5. Setting up Headers.
    6. The Content-Length header specifies the size of the current request.
    7. The Content-Range header indicates the range of bytes in the overall file that this request represents.
    8. The total length of the file is known before you can upload the first fragment of the file.
    9. All file Sizes in bytes. User's image

    Important: Your app must ensure the total file size specified in the Content-Range header is the same for all requests. If a byte range declares a different file size, the request will fail.

    • After setting up the header when we send the graph endpoint, we will receive nextExpectedRanges, if there are more byte ranges that need to be uploaded. pic55 Refer the link
    • Now in Content-Length you need to provide next remaining bytes to be uploaded less than 60Mib. and in Content-Range we need to provide next expected range what we get in response

    If deferCommit is false or unset, then the upload is automatically completed when the final byte range of the file is PUT to the upload URL. When the upload is completed, the server will respond to the final request with an HTTP 201 Created or HTTP 200 OK. The response body will also include the default property set for the driveItem representing the completed file.

    User's image

    You can the refer link for the reference.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra 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.