如何使用CSOM(Java Script)将图像上载到SharePoint Online(Office 365)图片库?

问题描述:

目前创建的图片库使用csom进入SharePoint Online(办公室365)



在主机网上我的上一个问题,现在尝试向该库添加一些图像,因此,将创建的Image文件夹转换为SharePoint Hosted App。如何实现上述任务

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


(&#uploadDocumentButton")。click(function(){

if(window.FileReader){

input = document.getElementById(" inputFile");

if(input){

file = input.files [0];

fr = new FileReader();

fr.onload = receivedBinary;

fr .readAsDataURL(文件);

}

}

else {

alert(" HTML5 FileSystem API)这个浏览器不完全支持。);

}

});



函数receivedBinary ()$

var clientContext = new SP.ClientContext(url);

web = client Context.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;我< 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);

}
("#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);
}