Hi,
I am trying to upload pdf file in document library with REST api using below code block in content editor web part. Pdf is getting added in the target folder of document library but seems it is getting corrupted as i am not able to view or open the file. The same code block is working fine if i use it in SharePoint Hosted App. Can anyone let me know what i am doing wrong in below code?
function UploadFile(arrayBuffer) { $.ajax({ url: "https://sp.sharepoint.com/sites/dev/_api/web/GetFolderByServerRelativeUrl('/sites/dev/Shared Documents')/Files/Add(url='/sites/dev/Shared Documents/newPDF.pdf',overwrite=true)", headers: {"Accept": "application/json; odata=verbose","X-RequestDigest": $("#__REQUESTDIGEST").val(),"content-length": arrayBuffer.length, }, method: "POST", contentType: "application/json;odata=verbose", binaryStringRequestBody: true, body: arrayBuffer, state: 'Update', success: function(data) { debugger; //var jsonObj = $.parseJSON(data.body); //complete(jsonObj.d); }, error: function(err) { alert('Error in addFile'); } }); }</script>
Thanks. Jaydeep.