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;

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

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;

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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