How to upload a large size file(more than 250MB) on sharepoint via rest API callout in JavaScript?

Parvez Alam 0 Reputation points
2023-07-17T12:00:39.69+00:00

I am trying to upload a large file on sharepoint via rest api callout using JavaScript but not able to upload files having size more then 250MB.

Below mentioned is the logic that I have implemented -

<html>
  <head>
    <title>File Upload with Fetch API</title>
  </head>
  <body>
    <form>
      <input type="file" id="fileInput" name="fileInput">
      <button type="button" id="uploadButton">Upload</button>
    </form>

    <script>
      const uploadButton = document.getElementById('uploadButton');
      const fileInput = document.getElementById('fileInput');
	  accesstoken='{ACCESS_TOKEN}';
      filename ='Test1.pdf';
      const endpoint = 'https://<Tenant Name>.sharepoint.com/sites/<SiteName>/_api/web/GetFolderByServerRelativeUrl(\'' + '/sites/<SiteName>/Shared%20Documents/<FolderName>' + '\')/Files/add(url=\'' + filename + '\',overwrite=true)';

        uploadButton.addEventListener('click', () => {

        const file = fileInput.files[0];

        const formData = new FormData();

        formData.append('file', file);

        fetch(endpoint, {

          method: 'POST',

          headers: {
            'Authorization': 'Bearer '+accesstoken,
            'Content-Type': 'multipart/form-data',
            'Accept': 'application/json; odata=nometadata',
            'X-RequestDigest':'<FORM_Digest>'
          },

          body: formData

        })

        .then(response => response.json())

        .then(data => {

          alert('File uploaded successfully!');

        })

        .catch(error => {

          alert('Error uploading file');

        });

      });

    </script>

  </body>

</html>


By this logic I am able to upload files on SharePoint but of size less than 250MB.

If I try to upload file greater than 250MB it throws error in response, which is below mentioned -

User's image

Please suggest some solution thanks in advance.

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-07-18T01:59:39.2166667+00:00

    Hi @Parvez Alam

    Please try to work around the limitation by uploading in parts
    You can refer to the following document
    https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-rest-reference/dn450841(v=office.15)?redirectedfrom=MSDN#bk_FileCollectionAdd

    User's image

    User's image

    User's image

    Here is a link for your reference:

    https://sharepoint.stackexchange.com/questions/287334/upload-files-250mb-via-sharepoint-rest-api


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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    0 comments No comments

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.