Andy Stobirski · May 19

%CSP.StreamServer not fully downloading file


I have a few Zen pages, one of which is implementation of %CSP.StreamServer which I'm using to download a PDF file, however, any file downloaded is 5Kb smaller than the original. This is the code I'm using:

Class GMECC.DocmanConnect.Pages.downloadGPNotOnHub Extends (, %CSP.StreamServer)
    ClassMethod GetId()
        Quit $Get(%request.Data("filepath",1))

    ClassMethod OnPreHTTP() As %Boolean
        set filepath = %request.Get("filepath")
        set tFs=##class(%Stream.FileCharacter).%New()
        set tFs.Filename=filepath
        set %response.ContentType = "application/pdf"
        do %response.SetHeader("Content-Disposition","attachment;filename="""_$P(filepath,"\",*)_"""")
        Do %response.SetHeader("Content-Length",tFs.SizeGet())
        Quit $$$OK

    ClassMethod OnPage() As %Status
        set myfile = ##class(%File).%New(%request.Get("filepath"))
        do myfile.Open("S")
        do myfile.OutputToDevice(myfile.SizeGet())	//myfile.OutputToDevice() 
        quit $$$OK

And it is called via a hyperlink as follows:


The resultant file is correctly interpreted as a PDF, given the appropriate file name etc, but is 5Kb smaller

Any thoughts?

Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.2.1 (Build 654U) Fri Mar 18 2022 06:09:35 EDT
0 85
Discussion (1)1
Log in or sign up to continue

I solved it.

I changed to OnPage() method to use a %Stream.FileCharacter as follows:

ClassMethod OnPage() As %Status
	set fs = ##class(%Stream.FileCharacter).%New()
	set fs.Filename = %request.Get("filepath")
	do fs.OutputToDevice()
	quit $$$OK