Greetings all,
I'm trying to create a form that allows users to upload a file from their local machines, which are actually virtual clients, to the SAS Server.
The structure of the application is basically a master Stored Process that calls one of two programs, depending on a macro variable named task.
The first program displays the form for the upload.
The second program actually is the one that should take care of uploading the file. At the moment is just a debug program because it's where I'm having problems on putting it to work.
The problem is I can't seem to access the file through the automatic macro variables _webin_* that should reference to information about the file that was selected in the upload form. I always get the warning message that the macro variables do not exist.
I would appreciate if you look at my code bellow and tell me what is missing.
Code for SP:
%global task;
%let stppath=/Stored Processes/rmdb/Test1;
%macro main;
%if &task = %str() %then %do;
%include sasprog(nps_stp_show_upload_screen);
%end;
%else %do;
%include sasprog(nps_stp_upload_file);
%end;
%mend main;
%main;
Code for program nps_stp_show_upload_screen:
data _null_;
file _webout encoding="UTF-8";
put "<form method='post' action='do'>";
put "<input type='hidden' name='_program' value='&stppath.' />";
put "<input type='hidden' name='task' value='upload_file' />";
put '<table border="0" cellpadding="5">';
put "<tr>";
put '<th>Choose a file to upload:</th>';
put '<td><input name="myfile" type="file" /></td>';
put '</tr>';
put '<tr>';
put '<td colspan="2" align="center"><input type="submit" value="OK" /></td>';
put '</tr>';
put '</table>';
put '</form>';
run;
Code for program nps_stp_upload_file:
data _null_;
file _webout encoding="UTF-8";
put "Fileref: &_WEBIN_FILEREF";
put "&_WEBIN_CONTENT_LENGTH";
put "&_WEBIN_CONTENT_TYPE ";
put "&_WEBIN_FILE_COUNT ";
put "&_WEBIN_FILEEXT ";
put "&_WEBIN_FILENAME ";
put "&_WEBIN_FILEREF ";
put "&_WEBIN_NAME ";
put "&_WEBIN_SASNAME ";
put "&_WEBIN_SASNAME_ORI ";
put "&_WEBIN_SASTYPE ";
put "&task";
run;
data _null_;
infile &_webin_fileref;
input;
put _infile_;
run;
The first program runs without problems. When I submit the form I can see that the second program is being called, I have values for macro vaiables task and myfile but none for the auto macro variables _webin_*.
The first step throws several warnings because of the missing references. The second one an error because the infile statement cannot resolve to a fileref.
Help please!
Regards,
PA
Hi,
The stored process is set to deliver streaming results, right?
Below is an example I have, based on Tricia Aanderud's excellent book 50 Keys to Learning Stored Processes (p 130.)
I noticed below specifies enctype="multipart/form-data":
<FORM ACTION="&_URL" method="post" enctype="multipart/form-data">
Maybe that is why your file isn't being uploaded??
data form;
format infile $char256.;
input;
infile=resolve(_infile_);
cards;
<HTML>
<BODY>
<H3> Hi %sysfunc(scan(&_username,1)), Please select a file to Upload </H3>
<FORM ACTION="&_URL" method="post" enctype="multipart/form-data">
<INPUT TYPE="HIDDEN" NAME="_program" VALUE="&_program">
<INPUT TYPE="HIDDEN" NAME="submit" VALUE="submitted">
<table border="0" cellpadding="5">
<tr><td>
<INPUT TYPE="file" NAME="attach1" />
</td></tr>
<tr><td>
<INPUT TYPE="submit" value="Upload">
</td></tr>
</table>
</FORM>
</BODY>
</HTML>
;
run;
Hi,
The stored process is set to deliver streaming results, right?
Below is an example I have, based on Tricia Aanderud's excellent book 50 Keys to Learning Stored Processes (p 130.)
I noticed below specifies enctype="multipart/form-data":
<FORM ACTION="&_URL" method="post" enctype="multipart/form-data">
Maybe that is why your file isn't being uploaded??
data form;
format infile $char256.;
input;
infile=resolve(_infile_);
cards;
<HTML>
<BODY>
<H3> Hi %sysfunc(scan(&_username,1)), Please select a file to Upload </H3>
<FORM ACTION="&_URL" method="post" enctype="multipart/form-data">
<INPUT TYPE="HIDDEN" NAME="_program" VALUE="&_program">
<INPUT TYPE="HIDDEN" NAME="submit" VALUE="submitted">
<table border="0" cellpadding="5">
<tr><td>
<INPUT TYPE="file" NAME="attach1" />
</td></tr>
<tr><td>
<INPUT TYPE="submit" value="Upload">
</td></tr>
</table>
</FORM>
</BODY>
</HTML>
;
run;
The part for enctype="multipart/form-data" was exactly what was missing.
Thank you for your help!
Best regards,
PA
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.