I must recommend that you check out this example from pg 70 of the SAS Stored Process Developers Guide. http://support.sas.com/documentation/cdl/en/stpug/61271/PDF/default/stpug.pdf
This is a pretty sweet example of how to upload a file from your machine (via Internet Explorer) into the SAS System.
A custom form can be created in html - or within data _null_ steps within a Stored Process. Modify the highlighted value= to the path of the subsequent stored process that you will run.
<form action="StoredProcessWebApplicationURL" enctype="multipart/form-data" method="post">
</form>
<input type="hidden" name="_program" value="/Path/StoredProcessName">
<table border="0" cellpadding="5">
<tbody>
<tr>
<th>Choose a file to upload:</th>
<td><input name="myfile" type="file" /></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" /></td>
</tr>
</tbody></table>
Then the stored process (the value that correspond to the path highlighted above "/Path/StoredProcessName") that runs when the user selects the "submit" button will need to use the hidden parameters available when using the 'file' input type. Table 5.5 in the document lists these values, and the example at the bottom of page 71 shows how to simply use a data null infile process to grab the contents of the uploaded file in SAS.
12 Comments
Angela
I re-wrote the html and got this working. Thanks for your help and speedy reply. Very much appreciated.
Thanks again,
Nigel
Awesome, thanks Nigel for letting me know!! Have a great weekend.
i am getting "Unsupported media type" when i try this.
And this is SAS 9.4, any idea?
Hi Nigel! Congratulations on the upgrade & continued use of this trick :)
According to mozilla.org "The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format.
The format problem might be due to the request's indicated Content-Type or Content-Encoding, or as a result of inspecting the data directly."
Are you still using the html form with encoding as: enctype="multipart/form-data"?
I have tried to use this method to upload a file but I get the followng error from my stored procedure:
WARNING: Apparent symbolic reference _WEBIN_FILEREF not resolved.
It's as if the SAS Macro variables are not getting passed into the stored proc. Any help/advice would be appreciated.
Nigel,
I have had a similar situation & the problem was that my web form html has a typo. These automatic variables are only created when the web form has an type="file" input line.
Such as:
<td><input name="myfile" type="file" /></td>
If this isn't the scenario for you, I would suggest creating a SAS Technical Support ticket or adding a comment on the Support Community for Stored Processes with some of your code.
Angela
Pingback: Troubleshooting a web file upload - Real BI for Real Users
As Sonny stated above - this is only recently available in 9.2.Workarounds in 9.1.3 would involve technology outside of SAS (such as JS/Java/etc) that I'm not as familiar with.
Do you know any workaround that it works within 9.1.3?
This is useful tip.Thanks for sharing
Thanks for pointing this out Sonny!Within 9.1.3 there are no reserved _WEBIN_ macro parameters available for use.http://support.sas.com/rnd/itech/doc9/dev_guide/stprocess/reserved.html
Must be mentioned that this only works in 9.2.