How to make response downloadable as file to user in MuleSoft

If you are trying to return a response to the client who made a request to API using a file, then you are at the right place. This article tells you How to return a response to a user in a file that is downloaded after hitting the API in MuleSoft. This post is applicable to both Mule 3 and Mule 4 versions.

How to get HTTP Status code in Mule 4



How to make your response payload downloadable as file to client in MuleSoft


Use cases:

  1. Client hits the API -> Flow Process happens here->Final Response is saved in a file and returned as response


Solution:
The solution is very simple. All you need to use is Set property component at the end of the flow and configure the Content-Disposition property like below



filename=MuleParsedFile_'+flowVars.filename: In the above example, The filename is fetched from the filename variable which is concatenated with MuleParsedFile_. The final file name will be something like below. You can form your own name

MuleParsedFile_file.txt

Syntax:


Property name: Content-Disposition

Property value: attachment; filename=<your file name goes here>

Example of Syntax:


Property name: Content-Disposition

Property value: #['attachment; filename=MuleParsedFile_'+flowVars.filename]




Post a Comment

0 Comments