Loading Files From Web Browser With Mule
This tutorial explains how to load files from your web browser using Mule 4.
Let's learn how to load files from a web browser in Mule 4.

Mule Code:
XML
xxxxxxxxxx
1
10
1
<flow name="file-uploadFlow">
2
<http:listener doc:name="Listener" config-ref="HTTP" path="upload-file"></http:listener>
3
<parse-template location="${apps.home}/web-page/hello.html"></parse>
4
</flow>
5
<flow name="file-uploadFlow1">
6
<http:listener config-ref="HTTP_Listener_config" path="upload"></http:listener>
7
<logger level="INFO" doc:name="Logger" message='File content : #[payload."parts"."file"."content"]'></logger>
8
<set-variable value="Success" variableName="status" ></set>
9
<parse-template location="${apps.home}/web-page/hello.html"></parse>
10
</flow>
You might also be interested in: Property File Handling in Mule 4
Note:
- Pass
${apps.home}in studio VM args or from property files. To run in studio:-Dapps.home=/Users/<user>/studio/workspace/upload/src/main/resources - In the code,
payload."parts"."file"."content", the object "file" is from the below HTML input name for file tag. If you change the name in HTML, then the same needs to be used.<input type="file" required="required" name="file"> - Instead of using a parse template, we can also use the Load static resources component.
HTML Code:
HTML
x
13
1
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
2
<title>File Upload</title>
3
</head>
4
<body>
5
<div class="container">
6
<form method="POST" action="/upload" enctype="multipart/form-data">
7
<h3>File Upload</h3>
8
<input type="file" required="required" name="file">
9
<button type="submit">Submit</button>
10
</form><br>
11
<font color="green"> #[if (vars.status != null) 'File upload: ' ++ vars.status else '']</font>
12
</div>
13
</body></html>
Note:
- Keep this HTML file in <app-name>/src/main/resources/web-page
- action="upload" invokes the above Mule flows
Further Reading
Mule: Load Properties as per the Environment (With Default Properties File)
HTML
MULE
Opinions expressed by DZone contributors are their own.