Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
currently created Picture Library using csom into SharePoint Online(office 365)

on host Web in my last question, now trying to add some Images to that Library, So for that created Image folder into SharePoint Hosted App. how to achive above task
Posted
Updated 8-Jul-15 21:58pm
v2

1 solution

$("#uploadDocumentButton").click(function () {
if (window.FileReader) {
input = document.getElementById("inputFile");
if (input) {
file = input.files[0];
fr = new FileReader();
fr.onload = receivedBinary;
fr.readAsDataURL(file);
}
}
else {
alert("The HTML5 FileSystem APIs are not fully supported in this browser.");
}
});

function receivedBinary() {
var url = _spPageContextInfo.webAbsoluteUrl;
var clientContext = new SP.ClientContext(url);
web = clientContext.get_web();
parentList = web.get_lists().getByTitle('Shared Documents');
fileCreateInfo = new SP.FileCreationInformation();
fileCreateInfo.set_url(file.name);
fileCreateInfo.set_overwrite(true);
fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
var arr = convertDataURIToBinary(this.result);
for (var i = 0; i < arr.length; ++i) {
fileCreateInfo.get_content().append(arr[i]);
}
this.newFile = parentList.get_rootFolder().get_files().add(fileCreateInfo);

clientContext.load(this.newFile, 'ListItemAllFields');
var item = this.newFile.get_listItemAllFields();

item.update();

clientContext.executeQueryAsync(onSuccess, onFailure);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900