BookmarkSubscribeRSS Feed
chithra
Quartz | Level 8
Hi,

I am reposting the same which i posted accidentally in the sas programming forum.

i need to read the attachemnt(file.zip) from the client and create a sas webservice(stored process) in sas.

what the storedprocess needs to do is, read the attachemnt from the request body and copy to one of the folder in the sas server.

Could anyone know about this?

we are using Restful webservice and can be tested in REST API/Client


Thanks,
Chithra
9 REPLIES 9
AllanBowe
Barite | Level 11

 Hi Chithra,

 

This is more a collection of pointers than a full solution, but should lead you on the right path.  

 

Step 1 - Loading your zip file to the SAS server

For this you can use a form, or ajax, in your web front end.  The form approach is documented here:  https://support.sas.com/documentation/cdl/en/stpug/61271/HTML/default/viewer.htm#a003254547.htm

 

Step 2 - Find and Unzip using SAS and save to folder

The file you uploaded will be stored in a macro variable named

_WEBIN_FILEREF1

To avoid a subsequent move of the folder, the best approach would be to unzip it directly to the target location.  You can do this using a pipe:

infile"unzip %sysfunc(pathname(&_WEBIN_FILEREF1)) -d &target_location" pipe;

Or with a pure sas approach - https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in....

 

Hope this helps!  SAS is a great platform for building web applications.  For further reference materials, check out the following:

 

 

There is also a SPWA tag on Sasensei with a number of tips on this topic.

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
chithra
Quartz | Level 8

Hi,

 

This is a new information for me and it really helps me.

STEP 1: I tried the html but I am getting "Unsupported Media Type", do I need to configure anything in the storedprocess which I created?

 

I created a stored process via SAS enterprise guide and copy the infile command you created there, but didn't add any prompts, datasouce targets etc.. is this the reason for the error message?

 

Thanks,

Chithra

chithra
Quartz | Level 8

can anyone help me here?

Kurt_Bremser
Super User

Where do you get the "Unsupported Media Type" message? When you hit "OK" in the web form, or in the SAS log of the stored process?

 

Please post your HTML code for the form, and the code of the stored process.

chithra
Quartz | Level 8

i created a sample stored process with out any content, just a %put comment.

The webservice is not triggered at all, if so we need to get any error atleast.

 

i triggered using REST client/postman  and through HTML form.

Both i get unsupported media type. 

 

<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>
AllanBowe
Barite | Level 11
As Kurt mentions, we need more information on what you are actually doing. Regarding the STP, be sure to create it WITHOUT headers / footers (stpbegin / end) and set it to have STREAM output to give you control over the response using _WEBOUT. No need for prompts.
/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
chithra
Quartz | Level 8

I created a stored process in SAS enterprise guide, with no logical code inside, 

select execution option in storedprocess server and doesn't add any data source targets etc..

 

file-->new-->storedprocess

 

through html form and using rest client/postman i uploaded a file with content type multipart/form-data and hit send button in rest client/api and ok button in html form and i am getting unsupported media type.

 

Does this means sas 9.4 is not suppporting this media type or do i need to change anyting in the stored process or any configuration changes in the sas server?

 

when i use other content types such as text/xml etc...i am not getting this message atleast i am getting some error.

AllanBowe
Barite | Level 11
can you post a screenshot? Are these messages coming from SAS or from Postman? Loading a file to a stored process should not (by itself) cause any errors.
/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
boemskats
Lapis Lazuli | Level 10

Assuming this is relating to STPs deployed as Web Services to the SASBIWS webapp, and called via the REST interface as documented here?

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1342 views
  • 3 likes
  • 4 in conversation