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:

  1. List : List all the files from a given directory

  2. Copy: Copies a file from one directory to another

  3. Create directory: Creates new directory

  4. Delete: Deletes a file

  5. Move: Moves a file from one directory to another

  6. On new or Updated files: Triggers when a new file created in a directory

  7. Read: Obtain the content and meta data of a file at a given path

  8. Write: Writes the content in a file pointed to given directory or path

  9. Rename: Renames a file

Walkthrough/Steps

  1. Read a File:

    1. Create new mule project in anypoint studio.

    2. Create the sample test file to read the content from local directory.

    3. Drag and drop file read operation from mule palette and configure the file path to read the file.

  1. Create a new Directory:

    1. Create new mule project in anypoint studio.

    2. Drag and drop file create directory operation from mule palette and configure the directory path to create new directory.

  1. List All Files and Directory:

    1. Create new mule project in anypoint studio.

    2. Drag and drop file List operation from mule palette and configure the directory path to list all files and directory.

  1. Copy a File:

    1. Create new mule project in anypoint studio.

    2. Drag and drop file Copy operation from mule palette.

    3. 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

  1. Move a File:

    1. Create new mule project in anypoint studio.

    2. Drag and drop file Move operation from mule palette.

    3. 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

    4. It deletes the file from source path.

  2. Write a File:

    1. Create new mule project in anypoint studio.

    2. Drag and drop file Move operation from mule palette.

    3. 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

  1. Rename a File:

    1. Create new mule project in anypoint studio.

    2. Drag and drop file Rename operation from mule palette.

    3. Configure the actual path and new name that will be used to rename the file.

  1. Delete a File:

    1. Create new mule project in anypoint studio.

    2. Drag and drop file Delete operation from mule palette.

    3. Configure the path of File or Directory that needs to be deleted.

  1. Trigger on New or Updated File:

    1. Create new mule project in anypoint studio.

    2. Drag and drop file On New or Updated File operation from mule palette.

    3. Configure the below parameters:

      1. Directory: provide the directory path

      2. Matcher: Use a matcher to filter the files

      3. 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

      4. Schedule Frequency: configure the frequency to poll the directory

d. Once the file is processed you can configure below parameters

  1. Auto Delete: file delete after processing default is false

  2. Move to directory: configure the directory for processed file

  3. Rename: rename file after processing

References (Blogs referred, Mule docs referred, videos referred etc)

File Connector - Mule 4 | MuleSoft Documentation