I am trying to use the REST Service to add an attachment in a SharePoint Hosted App I have created. The app first creates the Item via the CSOM, then it should upload the attachment via the REST SERVICE.
My code to add the attachment uses the SPSERVICES library:
$().SPServices({ operation: "AddAttachment", webURL: hostweburl, listName: listId.toString(), asynch: true, listItemID: newListItem.get_id(), fileName: fileInfo[itr].file.name, attachment: binary, completefunc: function (xData, Status) { alert("uploaded"); } });I have confirmed via FIDDLER that it is sending the correct SOAP packet:
<?xml version="1.0"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><AddAttachment xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>Documents</listName><listItemID>44254</listItemID><fileName>desktop.ini</fileName><attachment>//4NAAoAWwAuAFMAaABlAGwAbABDAGwAYQBzAHMASQBuAGYAbwBdAA0ACgBMAG8AYwBhAGwAaQB6AGUAZABSAGUAcwBvAHUAcgBjAGUATgBhAG0AZQA9AEAAJQBTAHkAcwB0AGUAbQBSAG8AbwB0ACUAXABzAHkAcwB0AGUAbQAzADIAXABzAGgAZQBsAGwAMwAyAC4AZABsAGwALAAtADIAMQA3ADkAOQANAAoA</attachment></AddAttachment></soap:Body></soap:Envelope>
I have tried using the document Name and also Document ID. I have confirmed the soap packet is correct. I tested the base64 content and again it is correct.
However I just get an "ERROR" back from jquery. .in fiddler the HTTP error is:
d9<html><head><title>Object moved</title></head><body><h2>Object moved to <a href="https://mine.sharepoint.com/_layouts/15/error.aspx?ErrorText=Request%20format%20is%20unrecognized%2E">here</a>.</h2></body></html> 0
However I can confirm the item has not been moved