DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • On-Demand-Schedulers With MuleSoft CloudHub APIs
  • Stop Poisoning Your Models: How I Built a CV Dataset Quality Toolkit I Can Reuse Forever
  • How to Verify Domain Ownership: A Technical Deep Dive
  • Streaming vs In-Memory DataWeave: Designing for 1M+ Records Without Crashing

Trending

  • When One MVP Is Really Four Systems: A Better Way to Plan Multi-Role Apps
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1
  • Chaos Engineering Has a Blind Spot. Agentic AI Lives in It.
  • Why DDoS Protection Is an Architectural Decision for Developers
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Loading Files From Web Browser With Mule

Loading Files From Web Browser With Mule

This tutorial explains how to load files from your web browser using Mule 4.

By 
Kasim Bekur user avatar
Kasim Bekur
·
Updated Mar. 10, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
18.1K Views

Join the DZone community and get the full member experience.

Join For Free

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:

  1. 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 
  2.  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"> 
  3. 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:

  1. Keep this HTML file in <app-name>/src/main/resources/web-page
  2. 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.

Related

  • On-Demand-Schedulers With MuleSoft CloudHub APIs
  • Stop Poisoning Your Models: How I Built a CV Dataset Quality Toolkit I Can Reuse Forever
  • How to Verify Domain Ownership: A Technical Deep Dive
  • Streaming vs In-Memory DataWeave: Designing for 1M+ Records Without Crashing

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook