BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PAzevedo
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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 Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

2 REPLIES 2
Quentin
Super User

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 Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
PAzevedo
Fluorite | Level 6

The part for enctype="multipart/form-data" was exactly what was missing.

Thank you for your help!

Best regards,

PA

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3906 views
  • 3 likes
  • 2 in conversation