PDF Attachment corrupted in Chrome but works in Firefox (saveResponseBodyAsAttachment with SOAP MTOM

Dominik9
Tera Guru

Hi experts

 

I am working on a SOAP integration in a ServiceNow test instance.
I send a SOAP request (with RESTMessageV2) and receive a PDF document as part of the response.

When I call saveResponseBodyAsAttachment(), the file is created and can be opened successfully in Firefox, but in Chrome the PDF shows as corrupted (“Failed to load PDF document”).

 

Here is the simplified Background Script:

var endpoint = "https://entity-api1-5.demo.abacus.ch/abaconnect/services/centraldossier_2023_00";
var r = new sn_ws.RESTMessageV2();
r.setEndpoint(endpoint);
r.setHttpMethod("POST");
r.setRequestHeader("Content-Type", "text/xml; charset=UTF-8");
r.setRequestHeader("SOAPAction", "find");
r.setRequestBody(soapBody); // omitted here for clarity

try {
    r.saveResponseBodyAsAttachment("incident", "57af7aec73d423002728660c4cf6a71c", "test_file.pdf");
    var response = r.execute();
} catch (e) {
    gs.error("Find call failed: " + e.message);
}

 

The response looks like this:

--MIMEBoundary_bba654f0ab939f1b8dd75f43202af6c8af71e539d94a4fb0
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.8ba654f0ab939f1b8dd75f43202af6c8af71e539d94a4fb0@apache.org>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope ...>
    ...
    <apt:Attachment>
        <apt:BinaryData>
            <apt:Name>filename.pdf</apt:Name>
            <apt:BinData>
                <xop:Include href="cid:filename.pdf"/>
            </apt:BinData>
        </apt:BinaryData>
    </apt:Attachment>
    ...
</soapenv:Envelope>
--MIMEBoundary_bba654f0ab939f1b8dd75f43202af6c8af71e539d94a4fb0
Content-Type: application/octet-stream
Content-ID: <filename.pdf>

%PDF-1.5
%����
7 0 obj
...

My questions:

  1. Do you see a problem with my approach?
  2. Is there a known issue with saveResponseBodyAsAttachment() when handling MTOM/XOP responses?

  3. Already tried to only save the part from %PDF-1.5 to %%EOF without any success to open the file then. 
  4. Has anyone found a reliable way to extract and store MTOM attachments so that the PDF is valid in all browsers?

  5. Do you have any other ideas on how to solve the issue?

Thanks a lot for your help!
Dominik

 

0 REPLIES 0