We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Corrupted Binary Files (PDF) when downloading from GCS via MID Server using RESTMessageV2

DoloLeNom
Tera Contributor

Hi Everyone,

I am facing a persistent issue where PDF files downloaded from Google Cloud Storage (GCS) via a MID Server are becoming corrupted. When the file reaches the browser, it shows "Something went wrong" or contains error text like "Invalid Credentials" instead of the actual PDF bytes.

Environment:

Source: Google Cloud Storage (GCS).

Bridge: MID Server (RESTMessageV2) using the Metadata URL for OAuth Token retrieval.

Trigger: Client-side UI Action using GlideAjax.

The Current Approach:

UI Action calls a Script Include via GlideAjax.

Script Include triggers RESTMessageV2 through the MID Server.

The Script Include waits for the ecc_queue response.

Once received, the response content is sent back to the client and converted into a Blob for download.

The Problems:

Binary Corruption: Since the MID Server returns the file as a string in the XML payload, the PDF binary data is being mangled by UTF-8 encoding.

Error Handling: If the GCS request fails (e.g., 401 Unauthorized), the JSON error message is being treated as the file content, resulting in a PDF that contains the text "Invalid Credentials."

File Size Limits: Files larger than 5MB are not appearing in the <output> tag of the ECC Queue, returning null instead.

0 REPLIES 0