Reputation: 101
I am uploading an excel file to a folder in Document library using Javascript in share point. IT is properly uploading if the excel size is less than 2 MB and if the excel size is more than 2 MB my code is going to the exception. Please help on how to upload a file which is more than 2 Mb in share point using Javascript. This is the Link I followed.
function uploadFile(arrayBuffer, fileName )
{
//Get Client Context,Web and List object.
var clientContext = new SP.ClientContext();
var oWeb = clientContext.get_web();
var oList = oWeb.get_lists().getByTitle('MyFolder');
//Convert the file contents into base64 data
var bytes = new Uint8Array(arrayBuffer);
var i, length, out = '';
for (i = 0, length = bytes.length; i < length; i += 1)
{
out += String.fromCharCode(bytes[i]);
}
var base64 = btoa(out);
//Create FileCreationInformation object using the read file data
var createInfo = new SP.FileCreationInformation();
createInfo.set_content(base64);
createInfo.set_url(fileName);
//Add the file to the library
var uploadedDocument = oList.get_rootFolder().get_files().add(createInfo)
listItem = uploadedDocument.get_listItemAllFields();
listItem.set_item('Title', 'Some Title');
listItem.update();
//Load client context and execcute the batch
clientContext.load(uploadedDocument,'ListItemAllFields');
clientContext.executeQueryAsync(Function.createDelegate(this, this.QuerySuccess), Function.createDelegate(this, this.QueryFailure));
element.value = '';
document.getElementById("getTitle").value = "";
}
function QuerySuccess()
{
//var id = uploadedDocument.get_listItemAllFields();
//here we can get all the fields
console.log('File Uploaded Successfully.');
swal("File Uploaded Successfully.");
}
function QueryFailure(sender, args)
{
console.log('Request failed with error message - ' + args.get_message() + ' . Stack Trace - ' + args.get_stackTrace());
swal(args.get_message());
}
Thanks for the Help.
Upvotes: 0
Views: 276