Rest – Sharepoint 2013 Add large files with rest api

filefile uploadrestsharepoint-2013upload

I am working on a project to copy files from one document library to another in Sharepoint 2013 via jquery and the rest api. My solution is based off of this http://techmikael.blogspot.com/2013/07/how-to-copy-files-between-sites-using.html

The following code works for smaller file sizes (64mb or less). However I am getting an error when attempting to copy larger files (128Mb and up). The addFileBinary function returns to the error callback with "Not enough storage is available to complete this operation." Is there a workaround for this? I am using IE11.

$(document).ready(function () 
{
    //Get binary data of file to copy
    getFileBinary(fromUrl, FileServerRelativeUrl, function (binary) 
    {    
        //Copy binary file data to new library
        addFileBinary(toUrl, newLibraryName, FileName, binary, function (newFile) 
        {
            alert("File Added");
        },null);

    },null);
}


function getFileBinary(url, filePath, complete, failure) 
{
    var executor = new SP.RequestExecutor(url);
    var info = {
        url: "_api/web/getfilebyserverrelativeurl('" + filePath + "')/$value",
        method: "GET",
        binaryStringResponseBody: true,
        success: function (data) {
            //binary data available in data.body
            complete(data.body);
        },
        error: function (err) {
            failure(err);
        }
    };
    executor.executeAsync(info);
}

function addFileBinary(url, libraryName, fileName, arrayBuffer, complete, failure) {
    var executor = new SP.RequestExecutor(url);
    var info = {
        url: "_api/web/GetFolderByServerRelativeUrl('" + libraryName + "')/Files/Add(url='" + fileName + "', overwrite=true)?$expand=ListItemAllFields,ListItemAllFields/ParentList",
        headers: {
            "Accept": "application/json; odata=verbose",
            "content-length": arrayBuffer.length,
        },
        method: "POST",
        contentType: "application/json;odata=verbose",
        binaryStringRequestBody: true,
        body: arrayBuffer,
        state: 'Update',
        success: function (data) {
            var jsonObj = $.parseJSON(data.body);
            complete(jsonObj.d);
        },
        error: function (err) {
            failure(err);
        }
    };
    executor.executeAsync(info);
}

I have done the following to try to correct this issue (None of it worked).

  • Changed the general settings of the web app to allow files up to 2047.
  • Increased the connection timeout setting in iis for Sharepoint.
  • Added maxRequestLength="2096128" executionTimeout="999999" to httpruntime in the web.config
  • Increased the maxAllowedContendLength in the web.config to 2147483647