The following figure shows a custom
input form that can be used to upload a single file to the stored
process server:
Here is an HTML example
for uploading a single file:
<form action="StoredProcessWebApplicationURL" method="post"
enctype="multipart/form-data">
<input type="hidden" name="_program" value="/Path/StoredProcessName">
<table border="0" cellpadding="5">
<tr>
<th>Choose a file to upload:</th>
<td><input type="file" name="myfile"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="OK"></td>
</tr>
</table>
</form>
In the preceding HTML
example, you must replace "
StoredProcessWebApplicationURL" with the path to the SAS Stored Process Web Application. This path
is usually
http://YourServer:8080/SASStoredProcess/do
, where
YourServer corresponds to the domain name of your stored process server. Similarly,
you need to specify the path and name of the stored process that you
want to execute after the file has been uploaded. You should specify
the exact values that are shown for the METHOD and ENCTYPE attributes
of the FORM tag.
The INPUT tag in the
preceding HTML example is used to create the
Browse button and text entry field in the preceding figure. The appearance
of this control might be different depending on which Web browser
you use, but the functionality should be the same. Clicking the
Browse button enables you to navigate to the file that
you want to upload. You can choose any file that you have access to.
This example uses the file
readme.txt
, which resides in the Windows directory
C:\temp
.
After you select a file
and click
OK, all form data is sent to the
SAS Stored Process Web Application, which forwards the data to the
stored process server. As a result, the following SAS macro variables
are created:
SAS Macro Variables
|
|
|
|
|
Specifies the size of
the file that was uploaded in bytes (supplied automatically by the
Web browser).
|
|
|
Specifies the content
type that corresponds to the file that was uploaded (supplied automatically
by the Web browser).
|
|
|
Specifies the number
of files that were uploaded.
|
|
|
Specifies the extension
of the file that was uploaded.
|
|
|
Specifies the name and
original location of the file that was uploaded.
|
|
|
Specifies the SAS fileref
that you can use to access the uploaded file. This fileref is assigned
for you by the SAS server.
|
|
|
Specifies the value
that corresponds to the NAME attribute of the INPUT tag.
|
Your stored process
has access to the uploaded file through the fileref that is stored
in the value of the _WEBIN_FILEREF macro variable. The following code
example returns the uploaded file to the client:
* Set the Content-type header;
%let RV = %sysfunc(stpsrv_header(Content-type, &_WEBIN_CONTENT_TYPE));
* Write the file back to the Web browser;
data _null_;
length data $1;
infile &_WEBIN_FILEREF recfm=n;
file _webout recfm=n;
input data $char1. @@;
put data $char1. @@;
run;
The preceding code example
shows how to use the _WEBIN_CONTENT_TYPE macro variable to set the
content-type header. This code also shows how to use the _WEBIN_FILEREF
macro variable to access the uploaded file.