Download File With Rest
Hello Everyone!
Following the example below i can download file only txt format, in other format(pdf,xls,rar) i have errors(can't open file),
So, how i will change code for download file in other format?
Thanks!
{
#dim %request As %CSP.Request
set filename="E:\Rest\"_file
set %response.ContentType=..GetFileContentType($p(filename,".",*))
do %response.SetHeader("Content-Disposition","attachment;filename="""_$p(filename,"\",*)_"""")
Set %response.NoCharSetConvert=1
Set %response.Expires=50
set file=##class(%File).%New(filename)
do file.Open("R")
do file.OutputToDevice()
Quit $$$OK
}
ClassMethod GetFileContentType(pFileType) As %String
{
if pFileType="txt" quit "text/plain"
if pFileType="rar" quit "application/x-rar-compressed"
if pFileType="pdf" quit "application/pdf"
if pFileType="docx" quit "application/msword"
if pFileType="xls" quit "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
quit ""
}