File Connector in Mule 4
Introduction
File connector support operations such as creating directories and copying, moving, renaming, and deleting files.
Trigger a flow when the new file created or modified.
Locking file so that no one can access file when the processing is going on
Operations of File Connector:
List : List all the files from a given directory
Copy: Copies a file from one directory to another
Create directory: Creates new directory
Delete: Deletes a file
Move: Moves a file from one directory to another
On new or Updated files: Triggers when a new file created in a directory
Read: Obtain the content and meta data of a file at a given path
Write: Writes the content in a file pointed to given directory or path
Rename: Renames a file
Walkthrough/Steps
Read a File:
Create new mule project in anypoint studio.
Create the sample test file to read the content from local directory.
Drag and drop file read operation from mule palette and configure the file path to read the file.
Create a new Directory:
Create new mule project in anypoint studio.
Drag and drop file create directory operation from mule palette and configure the directory path to create new directory.
List All Files and Directory:
Create new mule project in anypoint studio.
Drag and drop file List operation from mule palette and configure the directory path to list all files and directory.
Copy a File:
Create new mule project in anypoint studio.
Drag and drop file Copy operation from mule palette.
Configure the
Path: source and target path to copy the file.
Create parent directories: if you set the createParentDirectories to true, the connector will automatically create any missing directories else the operation will fail
Write Mode: there are write mode you can use while writing the file like APPEND,OVERWRITE,CREATE_NEW
Move a File:
Create new mule project in anypoint studio.
Drag and drop file Move operation from mule palette.
Configure the
Path: source and target path to move the file.
Create parent directories: if you set the createParentDirectories to true, the connector will automatically create any missing directories else the operation will fail
Write Mode: there are write mode you can use while writing the file like APPEND,OVERWRITE,CREATE_NEW
It deletes the file from source path.
Write a File:
Create new mule project in anypoint studio.
Drag and drop file Move operation from mule palette.
Configure the below parameters:
Path: provide path to write the file
Content: create the payload you want to write
Create parent directories: if you set the createParentDirectories to true, the connector will automatically create any missing directories else the operation will fail
Write Mode: there are write mode you can use while writing the file like APPEND,OVERWRITE,CREATE_NEW
Rename a File:
Create new mule project in anypoint studio.
Drag and drop file Rename operation from mule palette.
Configure the actual path and new name that will be used to rename the file.
Delete a File:
Create new mule project in anypoint studio.
Drag and drop file Delete operation from mule palette.
Configure the path of File or Directory that needs to be deleted.
Trigger on New or Updated File:
Create new mule project in anypoint studio.
Drag and drop file On New or Updated File operation from mule palette.
Configure the below parameters:
Directory: provide the directory path
Matcher: Use a matcher to filter the files
Watermark: Use the watermark parameter to only pick files that have been created or updated after the last poll was executed by default it is disabled
Schedule Frequency: configure the frequency to poll the directory
d. Once the file is processed you can configure below parameters
Auto Delete: file delete after processing default is false
Move to directory: configure the directory for processed file
Rename: rename file after processing
References (Blogs referred, Mule docs referred, videos referred etc)
Subscribe to my newsletter
Read articles from Nandinee Ramanathan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by