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/conten
t, 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.
- While Using Graph Endpoint
POST /me/drive/items/{itemId}:/{fileName}:/createUploadSession
, in response we will get uploadUrl. - 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.
- Authorization request header should be No Auth. The PUT query uses a pre-authenticated URL from the uploadUrl property.
- We need to select our file in binary option inside body.
- Setting up Headers.
- The Content-Length header specifies the size of the current request.
- The Content-Range header indicates the range of bytes in the overall file that this request represents.
- The total length of the file is known before you can upload the first fragment of the file.
- All file Sizes in bytes.
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. 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.
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".