From abccafab7b68a0f4535bf13fa233991336da9ea2 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Mon, 16 Nov 2020 11:08:01 +0100 Subject: [PATCH] feat: adding filref option to mp_streamfile.sas --- all.sas | 19 +++++++++++++------ base/mp_streamfile.sas | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/all.sas b/all.sas index ff0d23a8..064ab1fc 100644 --- a/all.sas +++ b/all.sas @@ -4111,7 +4111,7 @@ proc sql options &etls_syntaxcheck; %mend;/** - @file mp_streamfile.sas + @file @brief Streams a file to _webout according to content type @details Will set headers using appropriate functions (SAS 9 vs Viya) and send content as a binary stream. @@ -4129,6 +4129,7 @@ proc sql @param contenttype= Either TEXT, ZIP, CSV, EXCEL (default TEXT) @param inloc= /path/to/file.ext to be sent + @param inref= fileref of file to be sent (if provided, overrides `inloc`) @param outname= the name of the file, as downloaded by the browser @author Allan Bowe @@ -4139,6 +4140,7 @@ proc sql %macro mp_streamfile( contenttype=TEXT ,inloc= + ,inref=0 ,outname= )/*/STORE SOURCE*/; @@ -4154,7 +4156,7 @@ proc sql %end; %else %if &platform=SASVIYA %then %do; filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.zip' - contenttype='application/zip' + contenttype='application/zip' contentdisp="attachment; filename=&outname"; %end; %end; @@ -4168,7 +4170,7 @@ proc sql %end; %else %if &platform=SASVIYA %then %do; filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls' - contenttype='application/vnd.ms-excel' + contenttype='application/vnd.ms-excel' contentdisp="attachment; filename=&outname"; %end; %end; @@ -4181,7 +4183,7 @@ proc sql %end; %else %if &platform=SASVIYA %then %do; filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls' - contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' contentdisp="attachment; filename=&outname"; %end; %end; @@ -4214,7 +4216,7 @@ proc sql %else %if &contentype=HTML %then %do; %if &platform=SASVIYA %then %do; filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" - contenttype="text/html"; + contenttype="text/html"; %end; %end; %else %do; @@ -4222,7 +4224,12 @@ proc sql %return; %end; -%mp_binarycopy(inloc="&inloc",outref=_webout) +%if &inref ne 0 %then %do; + %mp_binarycopy(inref=&inref,outref=_webout) +%end; +%else %do; + %mp_binarycopy(inloc="&inloc",outref=_webout) +%end; %mend;/** @file mp_unzip.sas diff --git a/base/mp_streamfile.sas b/base/mp_streamfile.sas index 8f79d4eb..229c83cd 100644 --- a/base/mp_streamfile.sas +++ b/base/mp_streamfile.sas @@ -1,5 +1,5 @@ /** - @file mp_streamfile.sas + @file @brief Streams a file to _webout according to content type @details Will set headers using appropriate functions (SAS 9 vs Viya) and send content as a binary stream. @@ -17,6 +17,7 @@ @param contenttype= Either TEXT, ZIP, CSV, EXCEL (default TEXT) @param inloc= /path/to/file.ext to be sent + @param inref= fileref of file to be sent (if provided, overrides `inloc`) @param outname= the name of the file, as downloaded by the browser @author Allan Bowe @@ -27,6 +28,7 @@ %macro mp_streamfile( contenttype=TEXT ,inloc= + ,inref=0 ,outname= )/*/STORE SOURCE*/; @@ -42,7 +44,7 @@ %end; %else %if &platform=SASVIYA %then %do; filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.zip' - contenttype='application/zip' + contenttype='application/zip' contentdisp="attachment; filename=&outname"; %end; %end; @@ -56,7 +58,7 @@ %end; %else %if &platform=SASVIYA %then %do; filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls' - contenttype='application/vnd.ms-excel' + contenttype='application/vnd.ms-excel' contentdisp="attachment; filename=&outname"; %end; %end; @@ -69,7 +71,7 @@ %end; %else %if &platform=SASVIYA %then %do; filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls' - contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + contenttype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' contentdisp="attachment; filename=&outname"; %end; %end; @@ -102,7 +104,7 @@ %else %if &contentype=HTML %then %do; %if &platform=SASVIYA %then %do; filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" - contenttype="text/html"; + contenttype="text/html"; %end; %end; %else %do; @@ -110,6 +112,11 @@ %return; %end; -%mp_binarycopy(inloc="&inloc",outref=_webout) +%if &inref ne 0 %then %do; + %mp_binarycopy(inref=&inref,outref=_webout) +%end; +%else %do; + %mp_binarycopy(inloc="&inloc",outref=_webout) +%end; %mend; \ No newline at end of file