Gist SP REST
by dshilkret
JavaScript
//'use strict';
//*These Variables are to store Application URL and Sharepoint Web URL
var appWebUrl, hostWebUrl;
//*This step is to check that FileReader function is supported in the Browser In which REST File Uplode is being done.
jQuery(document).ready(function () {
// Check for FileReader API (HTML5) support.
if (!window.FileReader) {
alert('This browser does not support the FileReader API.');
}
// Get the add-in web and host web URLs.
appWebUrl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
hostWebUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
});
//*This is the Function from where Execution of the Program starts.
/*
When you will click on the Uplode Buttom This function will kick in to action and
all execution will start from here.
*/
// Upload the file.
// You can upload files up to 2 GB with the REST API.
function uploadFile() {
// Define the folder path for this example.
var serverRelativeUrlToFolder = '/shared documents';
// Get test values from the file input and text input page controls.
// The display name must be unique every time you run the example.
var fileInput = jQuery('#getFile');//* Here the File is Added
var newName = jQuery('#displayName').val();//* Name of file
// Initiate method calls using jQuery promises.
// Get the local file as an array buffer.
var getFile = getFileBuffer();//* This function will return File data stored in an FileBuffer as ArrayBuffer
/*
From Here it Deals with what to deal when File is stored in Array Buffer
*/
getFile.done(function (arrayBuffer) {
// Add the file to the SharePoint folder.
/*This Function will send the a REST query to save the file to a desired location
and return jQuery.ajax object.
*/
var addFile = addFileToFolder(arrayBuffer);
//When successfully updated file
addFile.done(function (file, status, xhr) {
// Get the list item that...