SOAP class: sample code

Sending attachments to the server

theSoapObject.addAttachment( filePath, "e5bb1dbe06c6448f4511f958bc18b50f", theFileMimeType, 0 );  
// this is DIME attachment
theSoapObject.setAttachmentSendType(0);

Remarks:

  • When adding an attachment, it is necessary to specify its href. This is usually mentioned somewhere in the SOAP body.
  • The SOAP server supports DIME attachments, therefore it is necessary to specify it like this:
    var Files =
     { "Attachment" : 
           {"Rendition" : "native",
             "Type" : theFileMimeType,
             "Content" : {"soapAttr" : "href=cid:e5bb1dbe06c6448f4511f958bc18b50f",
                           "soapValue" : ""}
            }
     };
    

Getting attachments from the SOAP response

var theDocId = parse( soapObject, "//Objects/Object/MetaData/BasicMetaData/ID" );
// get object from server
var theGetObjectsResult = getObject( s, theDocId, lockFile, theRenditionType );
// check returned result
var href = parse(theGetObjectsResult, "//Files/Attachment[Rendition='"+theRenditionType+"']/Content/@href");
if(href == "")
             {
              s.log( -1, "Server does not return file for document with id %1", theDocId );
              return "";
              }
                                
var idx = href.indexOf(":");
if(idx != -1) href = href.mid(idx + 1, href.length - (idx + 1));
// save attachment
var fName = parse(theGetObjectsResult, "//Objects/Object/MetaData/BasicMetaData/Name");
var fExt = getExtByMimeType( s, gLogonResponse, parse( theGetObjectsResult, "//Objects/Object/Files/Attachment/Type" ) );
var fileName = s.createPathWithName( fName + fExt, false );
if( theGetObjectsResult.saveAttachment( href, fileName ) )
              {
               s.log( -1, "Attachment saved %1", fileName );
               return fileName;
               }
               else
                   {
                    s.log( 3, "Cannot save attachment" );
                    return "";
                    }

Remarks: