Layer7 API Management

Sample Policy to save multipart message files to a remote ftp site. 

Apr 23, 2019 01:04 AM

This example developed for a support case, shows how to loop through multiple parts of a form-data message get the file name for each part and upload it to a remote ftp site. 

 

1. Sending multi-part message from PostMan client 

Here is the message we have in PostMan, where we have two .pdf files that are to be part of the posted content : 

 

2. Raw http data sent over the wire. 

Using fiddler we can see the raw data that is POST'ed when the message is sent to the gateway server.   Note the Content-Disposition header field that contains the filename : 

 

 

3. Policy that receives the request. 

 

The policy that receives the content loops over the ${requests.parts}, and processes each on separately. 

We isolate the "dataToSend" as a Message - (we picked application/octet-stream as content-type, as it needed to be hardcoded.  It would have been good to set it from the ${items.current.contentType} but that wasnt possible)

We also extract filename from the Content-Disposition header using regex.  

 

Then we call the "Route Via FTP"  assertion as per : 

passing in the ${filename} and the ${dataToSend} as the content. 

 

4. Running in the Debugger 

Here we can see the first pdf file being transferred. 

 

5. Transferred files 

And on the ftp site we can then see the two transferred files. 

 

The policy for the xfer process is attached to this article. 

 

Cheers - Mark

 

Included in knowledge doc link : 

https://comm.support.ca.com/kb/send-multiple-files-via-ftp-assertion/kb000131215 

Statistics
0 Favorited
14 Views
1 Files
0 Shares
6 Downloads
Attachment(s)
zip file
sample-ftpupload.xml.zip   1 KB   1 version
Uploaded - May 29, 2019

Tags and Keywords

Related Entries and Links

No Related Resource entered.