Send multiple files via FTP assertion

book

Article ID: 131215

calendar_today

Updated On:

Products

STARTER PACK-7 CA Rapid App Security CA API Gateway

Issue/Introduction

I try to send multiple files by using multipart/form-data method from Postman through FTP assertion on CA API gateway. However, it does not work as expected.

 

Environment

Gateway 9.2+ 
 

Resolution

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 : 

<Please see attached file for image>

User-added image
 

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 :

 

<Please see attached file for image>

User-added image

3. Policy that receives the request. 

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

<Please see attached file for image>

User-added image

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 : 

<Please see attached file for image>

User-added image

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. 

<Please see attached file for image>

User-added image
 

5. Transferred files 

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

<Please see attached file for image>

User-added image

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

Attachments

1558687239408000131215_sktwi1f5rjvs16f76.png get_app
1558687236536000131215_sktwi1f5rjvs16f75.png get_app
1558687234655000131215_sktwi1f5rjvs16f74.png get_app
1558687232873000131215_sktwi1f5rjvs16f73.png get_app
1558687230952000131215_sktwi1f5rjvs16f72.png get_app
1558687227711000131215_sktwi1f5rjvs16f71.png get_app
1558537204119sample-ftpupload.xml get_app