I want to upload image or create image in Sharepoint 2013 document library using rest api (Javascript)
my code to get bite array from input type file element is
var reader = new FileReader();
reader.onload = function (e) {
var byteArray = new Uint8Array(e.target.result);
uploadfile(file.name, byteArray);
}
reader.readAsArrayBuffer(file);
// this is function to upload file
function uploadfile(name, content) {
var createitem = new SP.RequestExecutor(appweburl);
createitem.executeAsync({
url: appweburl + "/_api/web/GetFolderByServerRelativeUrl('/sites/Filer/Filer/Lists/DropBoard/" + currentuser + "')/Files/Add(url='"+ name +"',overwrite=true)",
method: "POST",
headers: { "Accept": "application/octet-stream", "x-requestforceauthentication": true},
body: content,
success: function () { alert("done"); },
error: function () { alert("Error"); },
});
}
when I upload image this error found in consol Invalid field or parameter requestInfo.body.