You need to sign in to do that
Don't have an account?
Problem While Pushing the Documents using SOAP Message
Hi
I'm facing problem while opening the documents (PDF, doc) that was pushed to SDFC using SOAP Message. The PDF documents are successfully pushed to the folder but when I open them, there is an error message saying that "File Does not Begin with '%PDF-'
I'm trying to push the document using the SOAP request which is given below
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:enterprise.soap.sforce.com\" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance\">
<soapenv:Header>
<urn:SessionHeader>
<urn:sessionId>"+sessionID+"</urn:sessionId>
</urn:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<urn:create>
<urn:sObjects xsi:type="urn:Document">
<Name>Testing</Name>
<Body>readFileInBytes()</Body>
<Description>Testing Desc</Description>
<ContentType>application/pdf</ContentType>
<FolderId>folderID</FolderId>
</urn:sObjects>
</urn:create>
</soapenv:Body>
</soapenv:Envelope>
When I push the same document using the Web Service Client to SDFC, the PDF opens perfectly fine.
I'm setting the content type for the documents. I'm converting the documents in bytes and then populating the bytes array in the <Body> tag in the SOAP Message.
Can someone please suggest me what may be the problem?
Thanks
Rohit
Thanks for the Reply!
I encode the binary with the base64Binary and the modified request XML is given below:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">
<soapenv:Header>
<urn:SessionHeader>
<urn:sessionId>sessionID</urn:sessionId>
</urn:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<urn:create>
<urn:sObjects xsi:type="urn:Document">
<Name>Testing</Name>
<Body xsd:type="xsd:base64Binary">readFileInBytes()</Body>
<Description>testing</Description>
<ContentType>application/pdf</ContentType>
<FolderId>folderID</FolderId>
</urn:sObjects>
</urn:create>
</soapenv:Body>
</soapenv:Envelope>
The method for converting pdf to bytes is also given below which is passing a string as return. Initially I was passing the Byte[] array from the function but that also didn't helped.
public static String readFileInBytes() {
try {
File file = new File("PDF Testing.pdf");
InputStream is = new FileInputStream(file);
byte[] bytes = new byte[(int) length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
is.close();
StringBuffer bsq = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
bsq.append(bytes[i]);
}
return bsq.toString();
} catch (Exception e) {
return null;
}
}
With the above rquest, file is getting pushed to the document folder but I'm still getting the same error File Does not begin with '%PDF-'.
Please suggest what needs to be updated.
Thanks
Rohit