code: function addFileToFolder(arrayBuffer) {
              // Construct the endpoint.
              var fileCollectionEndpoint = String.format(spFormFactory.getFileEndpointUri(_spPageContextInfo.webAbsoluteUrl, doclibname, foldername) + "/add(overwrite=true, url='{0}')", fileuniquename);
  
              // Send the request and return the response.
              // This call returns the SharePoint file.
  
              return jQuery.ajax({
                          url: fileCollectionEndpoint,
                          type: "POST",
                          data: arrayBuffer,
                          processData: false,
                          headers: {
                              "accept": "application/json;odata=verbose",
                              "X-RequestDigest": $("#__REQUESTDIGEST").val()
                              //,"content-length": arrayBuffer.byteLength
                          }
                      });
          }
docs: }, onError); Add the file to the file collection in the Shared Documents folder.