I did a search for STRINGSTACK. Then I was able to solve this issue by changing Write param.%ToJSON() to Do param.%ToJSON()

This is in Docs for %ToJSON():

method %ToJSON(outstrm As %Stream.Object) as %String

Convert a %DynamicAbstractObject into a JSON string.

outstrm is optional. There are a number of possibilities:
(1) Parameter outstrm is not defined and the method is called via 'DO'. In this case the JSON string is written to the current output device.
(2) Parameter outstrm is not defined and the method is called as an expression. In this case the JSON string becomes the value of the expression.
(3) Parameter outstrm is defined. If it is %Stream object then the JSON string will be written to the stream. If outstrm is present but not an object then it is presumed to be a fully qualified file specification. In that case, a %Stream.FileCharacter stream is created, linked to that file and the JSON string is written to that stream. On completion, this stream is saved. The full path to the file must be defined. If outstrm is an object but is not an instance of %Stream.Object then an exception will be thrown.

Here is my lookFile method which gets the stream for %Set:

ClassMethod lookFile(pFile As %String = "https://jira.devops.myserver.com/my-jira/plugins/servlet/raven/attachmen... 1343.docx", pFileNew As %String = "") As %Stream.Object

{

    Set q = """"

    Set tData = q_pFile_q

    Set tFileOutlog = "/ICS/jira/wlogDATA"

    Set tFileOutput = "/ICS/jira/wgetDATA1343.docx"

    Set tSC = ##class(Oliver.ZF).JiraGet(tData,tFileOutput,tFileOutlog)

    ;

    Set tEncodeFN = ..GetEncodeFilename(pFile)

    Set tEncodePath = "/ICS/jira/"

    Set pEncode = tEncodePath_tEncodeFN

    ;

    Set tEncodedFilename = ##class(Oliver.Base64).B64EncodeWordDoc(tFileOutput,pEncode)

    Set pStream = ..GetStream(pEncode)

    Quit pStream

Why do you say the stream is typically a binary stream?

This is the method where I get the Stream:

ClassMethod GetStream(pFile As %String = "/tmp/shortObjectFile.txt") As %Stream.Object

{

    Set pStream = ##class(%Stream.FileCharacter).%New()

    Set pStream.Filename = pFile

    Quit pStream

}

The code to produce the encoded file will be in my next response.

Note: Base 64 encoding is not able to encode a string which contains unicode (2 byte) characters. If you need to Base 64 encode an unicode string, you should first translate the string to UTF8 format, then encode it. s BinaryText=$ZCONVERT(UnicodeText,"O","UTF8")
s Base64Encoded=$system.Encryption.Base64Encode(BinaryText)
Now to Decode it:
s BinaryText=$system.Encryption.Base64Decode(Base64Encoded)
s UnicodeText=$ZCONVERT(BinaryText,"I","UTF8")

I also have a Business Operation that sometimes experiences failures. My Reply Code Actions setting is E=R, my Retry Interval is 60, my Failure Timeout is -1. When a message fails, it retries after 60 seconds. This Business Operation is called from a BPL.

Connect Timeout (5) and Response Timeout (30) are the default values.

We usually do not get timeout, but we sometimes receive 500 Internal Server Error. In this case I check the response in BPL and initiate a retry.