I have seen files transferred inside JSON and I want to try it here. Before (now) I have this code to generate response object:

Set context.Response = ""
 If 1=request.%IsA("EnsLib.HTTP.GenericMessage") {
   If (context.StatusLine = "") {
      Set context.StatusLine = "HTTP/1.1 200 OK"
   }
   If (##class(%File).Exists(context.Outputfile)) {
     Set tStream = ##class(%Stream.FileBinary).%New()
     Set tSC = tStream.LinkToFile(context.Outputfile)
     If $$$ISERR(tSC) Do ##class(Oliver.Util).DebugStatus(tSC)
   }

   //Set tSC = tmp.%Save()
   Set context.Response=##class(EnsLib.HTTP.GenericMessage).%New($Get(tStream),,request.HTTPHeaders)
   Do context.Response.HTTPHeaders.SetAt("application/pdf","Content-Type")
   Do context.Response.HTTPHeaders.SetAt(context.StatusLine,"StatusLine")
   Set tSC = context.Response.%Save()
 }

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

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")