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
Newsletter
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
  • Why 200 OK Is the Most Dangerous Lie in Enterprise Integration
  • 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

Trending

  • How to Build Your Own AI SRE From Scratch
  • Introduction to Error Prone: How to Catch Bugs at Compile Time
  • Why AI Agents Need a Shared Enterprise Ontology
  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Updated Mar. 10, 20 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
18.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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
  • Why 200 OK Is the Most Dangerous Lie in Enterprise Integration
  • 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

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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