List AddAttachment

Sep 26, 2014 at 7:21 PM
Edited Sep 26, 2014 at 7:21 PM
I'm trying to figure out what i'm doing wrong here.

I'm using javascript file reader to get the contents of a file as binary.

When I try to add the attachment, the XML/SOAP is containing literally [object ArrayBuffer] instead of the actual Array.
var ID = 11; //some other truncated code but it is getting the correct ID into this variable

var reader = new FileReader();
reader.onload = function (event) {

    var fileName = document.getElementById('upload').files[0].name; 
        operation: "AddAttachment",
        async: false,
        listName: "ListTest",
        listItemID: ID,
        fileName: fileName,
        completefunc: function (xData, Status) {
The SOAP messagegetting sent to sharepoint server
        <AddAttachment xmlns=''>
            <attachment>[object ArrayBuffer]</attachment>
Any advice on what i'm doing wrong here? Why is it converting the actual array into the string [object ArrayBuffer]
Sep 26, 2014 at 8:13 PM
Edited Sep 26, 2014 at 8:18 PM
Ok i figured it out... it should be obvious I needed to base 64 encode the array.

I was trying to pass it directly because MSDN link shows
[SoapDocumentMethodAttribute("", RequestNamespace="", ResponseNamespace="", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public string AddAttachment (
    string listName,
    string listItemID,
    string fileName,
    byte[] attachment
Shows the attachment parameter is a byte[] but of course that doesn't make sense in a SOAP message, i was wrongly assuming from this comment:
A byte array that contains the file to attach by using base-64 encoding.
that the SPServices was doing the base-64 encoding
Sep 28, 2014 at 8:56 AM