Functionality to upload files onto the SAS server (from 9.2 on) is available using stored processes and an html input type="file". I introduced this topic last year in my blog post using the SAS Stored Process Developer Guide sample. Of course, it is never as easy as the sample is it? Over the past year I have used this functionality several times and believe me I have had my share of troubleshooting these implementations. So if you are still considering using custom forms with web file uploads, here is a list of items to consider during development.
- Access to PIPE
- File level security
- Don't use empty files (0 KB)
One of the requests was to not just use the file for some processing, but to store the actual file on the physical server. My first attempt was to use the filename PIPE functionality. Such as within UNIX, we would use the copy command cp to move a file from the source location (contained in the the automatic macro variable &_WEBIN_FILEREF) to the new location /uploadfiles and maintain the original file name (using the other macro variable &_WEBIN_FILENAME).
filename trans PIPE "cp &_WEBIN_FILEREF /uploadfiles/&_WEBIN_FILENAME"; data _null_; infile trans; run; |
However this requires access to pipe. By default, this functionality is disabled because with this type of access you can conceivably run commands that can delete or wreak other unimaginable havoc on a machine that is not locked down appropriately on the physical side.
The access to pipe error message looks like this:
ERROR: Insufficient authorization to access PIPE.
ERROR: Error in the FILENAME statement.
Besides enabling access, which in some situations requires an act of congress, there is another way to copy the file from your temporary web location onto the server. Use the RC = function RENAME to move the file over. (Another good reason to keep an eye out for SASCommunity.org Tips of the Day.)
data _null_; location=pathname("&&_WEBIN_FILEREF"); filename="c:\uploadfiles\"||strip("&_WEBIN_FILENAME"); rc = rename(strip(location), strip(filename),'file'); run; |
Once you have the rename function setup (or access to pipe enabled), there is still a small issue around file level security. If the physical folder is locked down, no one can write to it. So what level of security is required? Since this functionality is only available to the stored process server the SASSRV account must have write access to the location.
The tricky thing is that no errors will be produced for the user in the SAS Stored Process window with the RENAME function, its just no file will be written into the target folder location (in this case c:\uploadfiles). So just grant sassrv RW (read and write) access to the folder structure and retest.
One final issue was that during my testing, I was using an empty text file on my desktop. It had a name but 0 content. And guess what? It just doesn't work. Of course, I thought it was my custom form or something with the stored process. But after finally trying another file, I realized that when the file is just empty the &_WEBIN_FILENAME and &_WEBIN_FILEREF macros are not generated.
Have any of you started using the file upload capabilities in stored processes? Any other tips & tricks out there?
12 Comments
I've tried this a few different ways (as opposed to reading in a file as binary, and then writing it to the new location) and I continue to get a RC value of 1. I tried hard-coding a file on my SAS server and it works, but once I go back to this format (pulling from temp location to store it somewhere else) I get rc=1.
Is there any way to troubleshoot this further to see why its not working?
Hi Ben,
I have had issues with web forms before. One simple > sign off and it all goes haywire.
Therefore I would recommend testing the form html code itself.
Another option is to include %put statements to output more information to the log file.
It might just be that your copy command has an incorrect path.
~ Angela
If i am storing the file
in Server location D:uploadedsample.wmv -- video file or text file.
using Hyperlink anchor tag can i get it . Can you please suggest what method to approach. my requirment is using hyperlink need to access store files in server drive using STORE PROCESS.
-zeelan
You will need to place the wmv file on the server in a location that is enabled for web access. In your first example "server:port/SASStoredProcess/video/SportsNotesBackground.wmv" you would need to store on the server in the web application location such as: "C:jboss-4.2.0.GAserverSASServer1deploy_sassas.storedprocess9.2.earsas.storedprocess.warvideoSportsNotesBackground.wmv"
This directory is where jBoss resides on my machine - obviously this could be dramatically different for your environment.
Also - this requires that your .ear files are exploded into physical folders and a new directory (video) is created. More information on exploding .ear files can be found at:
http://blogs.sas.com/content/bi/2009/09/11/jboss-performance-improvement/
For more ideas about storing files for web viewing, check out my prior blog post:
http://blogs.sas.com/content/bi/2010/08/03/need-a-place-to-put-other-web-viewable-files/
This actually is a better place - since it is not affected by upgrades/redeployments of the SAS Web Applications. If you store files in StoredProcess/video as suggested earlier, the folder and contents will be wiped with each upgrade/rebuild.
Thank you Angella,
I will check this .Is there any why if i store it in drive location (D:) of server not in Jboss web server . :)
You can point to files using a file:// href tag (such as: http://www.codingforums.com/showthread.php?t=36746)
Or you can modify the jBoss configuration to include files in another folder. (such as: http://docs.jboss.org/jbportal/v2.7.1/referenceGuide/html/configuration.html)
Hi Angela,
Right now i am looking for same kind of requirment for one of customer .I have some doudts like
when we are uploading file (Any format) from local computer to SAS server /other sytem location.
if /uploadfiles/&_WEBIN_FILENAME" is other system(server) location is we need to give complete path example : in server i want to store are D: drive in specific folder how i need to proceed and also it will helpfull if you explain about how to download same file to local computer
Thanks,
Zeelan -
The rc=rename step will copy any file format from the upload process onto a physical folder that is available to the SAS server.
Here are some additional comments around that data step:
/*#1 Pathname function generates the server location for the temporary file you just uploaded into the system. Such as c:sas temporary filestn20482word_doc_uploaded.docx*/
location=pathname("&_WEBIN_FILEREF");
/*#2 the next line generates a full path to where you would like to store the file on the server. in your case change c:uploadfiles to d:path_wherever*/
filename="c:uploadfiles"||strip("&_WEBIN_FILENAME");
/*#3 rc= using a rename function this takes the file located in the full path (generated in #1 above) and moves the file into the physical path on the server (derived in #2 above).*/
rc = rename(strip(location), strip(filename),'file');
Hope this helps!
Angela
Angela,
Thanks for quick replay.This will certainly help me out
My requirement is i need to create a HTML page in one store process from where i need to give option to user where he can upload file from his local system and after submit STORE Process it will call one one stp and which should upload this selected file to SAS server location.so i think in second store process above suggested code will work .
One more request did you have any idea about download file logic using stored process using HTML FORM.
Thanks,
Zeelan
Th
Zeelan,
The blog post on uploading a file via the web into sas provides an example of what the first stored process in your flow could look like.
~ Angela
Hi Angela,
Thanks for detail explaination .I am able to upload the file in SAS server using above method .Can you please help me out how can i download same file from server and view it. I mean to say can i create a Source File
SportsNotesBackground.wmv
option Two:
Source File
SportsNotesBackground.wmv
Can you please suggest which will best method can i access like abov that.
Thanks,
Zeelan
Excellent tip! For handling files going the other way -- for download -- I've used this technique to copy a file from the SAS server to _WEBOUT, byte-for-byte.