File Connector Reference - Mule 4
File Connector v1.3
Anypoint Connector for File (File Connector) manipulates file systems mounted on a host operation system.
This class serves as both extension definition and configuration. Operations are based on the standard BaseFileSystemOperations
.
Release Notes: File Connector Release Notes
Configurations
Default Configuration
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Name |
String |
The name for this configuration. Connectors reference the configuration with this name. |
x |
|
Connection |
The connection types that can be provided to this configuration. |
x |
||
Default write encoding (DEPRECATED) |
String |
This parameter is deprecated and is ignored. |
||
Number |
Wait time between size checks to determine if a file is ready to read. This allows a file write to complete before processing. If no value is provided, the check is not performed. When enabled, Mule performs two size checks, waiting the specified time between calls. If both checks return the same value, the file is ready to be read. This attribute works in tandem with Time between size check unit. |
|||
Time Between Size Check Unit |
Enumeration, one of:
|
A Time unit that qualifies the Time between size check attribute. |
|
|
Expiration Policy |
Configures the minimum amount of time that a dynamic configuration instance can remain idle before the runtime considers it eligible for expiration. This does not mean that the platform will expire the instance at the exact moment that it becomes eligible. The runtime will actually purge the instances when it sees it fit. |
Connection Types
Local FileSystem Connection
A Connection Provider that provides instances of File System from instances of File Connector.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Working Directory |
String |
The directory to consider the root of every relative path used with this connector. If not provided, it defaults to the value of the |
||
Reconnection |
When an application deploys, a connectivity test is performed on all connectors. If set to |
Associated Sources
Copy
<file:copy>
Copies the file or directory specified in Source Path into the Target Path. The source path can be either a file or a directory. If it points to a directory, then it is copied recursively.
If the target path doesn’t exist, and neither does its parent, then a parent folder is created if Create parent directories is set to true
. If Create parent directories is set to false
, then a FILE:ILLEGAL_PATH
error is thrown.
If Overwrite is set to true
and the target file already exists, then the target file is overwritten. Otherwise, a FILE:FILE_ALREADY_EXISTS
error is thrown.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Configuration |
String |
The name of the configuration to use. |
x |
|
Source Path |
String |
The path to the file to be copied. |
x |
|
Target Path |
String |
The target directory where to copy the file. |
x |
|
Create Parent Directories |
Boolean |
Whether or not to create parent directories if they don’t exist. |
|
|
Overwrite |
Boolean |
Whether or not to overwrite the file if the target destination already exists. |
|
|
Rename To |
String |
The new name for the copied file. If not provided, original file name is kept. |
||
Reconnection Strategy |
A retry strategy in case of connectivity errors. |
Create Directory
<file:create-directory>
Creates a new directory on Directory path.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Configuration |
String |
The name of the configuration to use. |
x |
|
Directory Path |
String |
The new directory’s name. |
x |
|
Reconnection Strategy |
A retry strategy in case of connectivity errors. |
Delete
<file:delete>
Deletes the file that the path field points to, provided that the file is not locked.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Configuration |
String |
The name of the configuration to use. |
x |
|
Path |
String |
The path to the file to be deleted. |
x |
|
Reconnection Strategy |
A retry strategy in case of connectivity errors. |
List
<file:list>
Lists all the files in the Directory path that match a matcher.
If the listing encounters a directory, the output list includes its contents depending on the value of the Recursive parameter.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Configuration |
String |
The name of the configuration to use. |
x |
|
Directory Path |
String |
The path to the directory to be listed. |
x |
|
Recursive |
Boolean |
Whether to include the contents of subdirectories. |
|
|
File Matching Rules |
A matcher used to filter the output list. |
|||
Number |
Wait time between size checks to determine if a file is ready to read. |
|||
Time Between Size Check Unit |
Enumeration, one of:
|
Time unit to be used in the wait time between size checks. |
||
Streaming Strategy |
|
Configure if repeatable streams should be used and their behavior. |
||
Target Variable |
String |
The name of a variable on which the operation’s output is placed. |
||
Target Value |
String |
An expression to evaluate against the operation’s output and the outcome of that expression is stored in the target variable. |
|
|
Reconnection Strategy |
A retry strategy in case of connectivity errors. |
Output
Type |
Array of Message of [CursorProvider] payload and [Local File Attributes] attributes |
Move
<file:move>
Moves the file or directory from the Source Path into the Target Path. The source path can be either a file or a directory. If it points to a directory, then it will be moved recursively.
If the target path doesn’t exist, and neither does its parent, then a parent folder is created if Create parent directories is set to true
. If Create parent directories is set to false
, then a FILE:ILLEGAL_PATH
error is thrown.
If the target file already exists, then it will be overwritten if Overwrite is set to true
. If Overwrite is set to false
, a FILE:FILE_ALREADY_EXISTS
error will be thrown.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Configuration |
String |
The name of the configuration to use. |
x |
|
Source Path |
String |
The path to the file to be copied. |
x |
|
Target Path |
String |
The target directory. |
x |
|
Create Parent Directories |
Boolean |
Whether or not to attempt creating any parent directories which don’t exists. |
true |
|
Overwrite |
Boolean |
Whether or not overwrite the file if the target destination already exists. |
false |
|
Rename To |
String |
Moved file’s new name. If not provided, original file name is kept. |
||
Reconnection Strategy |
A retry strategy in case of connectivity errors. |
Read
<file:read>
Obtains the content and metadata of a file at a given path. The operation itself returns a Message which payload is a InputStream with the file’s content, and the metadata is represent as a LocalFileAttributes object that’s placed as the message Message#getAttributes()
attributes.
If the lock parameter is set to true, then a file system level lock is placed on the file until the input stream this operation returns is closed or fully consumed. Because the lock is actually provided by the host file system, its behavior might change depending on the mounted drive and the operation system on which Mule is running. Take that into consideration before blindly relying on this lock.
This method also makes a best effort to determine the MIME type of the file being read. The file’s extension is used to make an educated guess on the file’s MIME type. The user also has the chance to force the output encoding and mimeType
through the outputEncoding
and outputMimeType
optional parameters.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Configuration |
String |
The name of the configuration to use. |
x |
|
File Path |
String |
The path to the file to be read |
x |
|
Lock |
Boolean |
Whether or not to lock the file. Defaults to false. |
false |
|
Number |
Wait time between size checks to determine if a file is ready to be read. |
|||
Time Between Size Check Unit |
Enumeration, one of:
|
time unit to be used in the wait time between size checks. |
||
Output Mime Type |
String |
The MIME type of the payload that this operation outputs. |
||
Encoding |
String |
The encoding of the payload that this operation outputs. |
||
Streaming Strategy |
|
Configure if repeatable streams should be used and their behavior |
||
Target Variable |
String |
The name of a variable on which the operation’s output will be placed |
||
Target Value |
String |
An expression to evaluate against the operation’s output and the outcome of that expression will be stored in the target variable |
#[payload] |
|
Reconnection Strategy |
A retry strategy in case of connectivity errors. |
Rename
<file:rename>
Renames the file pointed by the path to the name provided on the to
parameter. The to
argument should not contain any path separator. FILE:ILLEGAL_PATH is thrown if this precondition is not honored.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Configuration |
String |
The name of the configuration to use. |
x |
|
Path |
String |
The path to the file to be renamed. |
x |
|
New Name |
String |
The file’s new name. |
x |
|
Overwrite |
Boolean |
Whether or not overwrite the file if the target destination already exists. |
false |
|
Reconnection Strategy |
A retry strategy in case of connectivity errors. |
Write
<file:write>
Writes the content into the file pointed by path.
If the directory on which the file is attempting to be written doesn’t exist, then the operation will either throw FILE:ILLEGAL_PATH error or create such folder depending on the value of the createParentDirectory.
If the file itself already exists, then the behavior depends on the supplied mode.
This operation also supports locking support depending on the value of the lock argument, but following the same rules and considerations as described in the read operation.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Configuration |
String |
The name of the configuration to use. |
x |
|
Path |
String |
The path of the file to be written |
x |
|
Content |
Binary |
The content to be written into the file. Defaults to the current Message payload |
#[payload] |
|
Encoding (DEPRECATED) |
String |
This parameter is deprecated and does nothing if configured. |
||
Create Parent Directories |
Boolean |
Whether or not to attempt creating any parent directories which don’t exists. |
true |
|
Lock |
Boolean |
Whether or not to lock the file. Defaults to false |
false |
|
Write Mode |
Enumeration, one of:
|
a FileWriteMode. Defaults to OVERWRITE |
OVERWRITE |
|
Reconnection Strategy |
A retry strategy in case of connectivity errors. |
Sources
On New or Updated File
<file:listener>
Polls a directory looking for files that have been created or updated. One message is generated for each file that is found.
The key part of this functionality is how to determine that a file is actually new.
These are the strategies for that:
-
Set the
autoDelete
parameter totrue
: This deletes each processed file after it has been processed, causing all files obtained in the next poll to be necessarily new. -
Set
moveToDirectory
parameter: This moves each processed file to a different directory after it has been processed, achieving the same effect asautoDelete<
but without loosing the file. -
Use the watermarkMode parameter to only pick files that have been created/updated after the last poll was executed.
A matcher can also be used for additional filtering of files.
Parameters
Name | Type | Description | Default Value | Required |
---|---|---|---|---|
Configuration |
String |
The name of the configuration to use. |
x |
|
Directory |
String |
The directory on which polled files are contained. |
||
Recursive |
Boolean |
Whether or not to also files contained in sub directories. |
true |
|
Matcher |
A matcher used to filter events on files which do not meet the matcher’s criteria. |
|||
Watermark Mode |
Enumeration, one of:
|
Controls whether or not to do watermarking, and if so, if the watermark should consider the file’s modification or creation timestamps |
DISABLED |
|
Number |
Wait time in milliseconds between size checks to determine if a file is ready to be read. This allows a file write to complete before processing. You can disable this feature by omitting a value. When enabled, Mule performs two size checks waiting the specified time between calls. If both checks return the same value, the file is ready to be read. |
|||
Time Between Size Check Unit |
Enumeration, one of:
|
A Time unit that qualifies the Time between size check. |
||
Output Mime Type |
String |
The MIME type of the payload that this operation outputs. |
||
Encoding |
String |
The encoding of the payload that this operation outputs. |
||
Primary Node Only |
Boolean |
Whether this source should be executed only on the primary node when running in a cluster. |
||
Scheduling Strategy |
scheduling-strategy |
Configures the scheduler that triggers the polling. |
x |
|
Streaming Strategy |
|
Configure if repeatable streams should be used and their behavior. |
||
Redelivery Policy |
Defines a policy for processing the redelivery of the same message |
|||
Reconnection Strategy |
A retry strategy in case of connectivity errors |
|||
Auto Delete |
Boolean |
Whether each file should be deleted after processing or not. |
false |
|
Move To Directory |
String |
If provided, each processed file will be moved to a directory pointed by this path. |
||
Rename To |
String |
This parameter works in tandem with Move to directory. Use this parameter to enter the name under which the file should be moved. Do not set this parameter if moveToDirectory hasn’t been set as well. |
||
Apply Post Action When Failed |
Boolean |
Whether any of the post actions (Auto delete and Move to directory) should also be applied in case the file failed to be processed. If set to |
|
Types
Reconnection
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Fails Deployment |
Boolean |
When the application is deployed, a connectivity test is performed on all connectors. If set to true, deployment will fail if the test doesn’t pass after exhausting the associated reconnection strategy |
||
Reconnection Strategy |
The reconnection strategy to use |
Reconnect
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Frequency |
Number |
How often in milliseconds to reconnect. |
||
Count |
Number |
How many reconnection attempts to make. |
||
blocking |
Boolean |
If false, the reconnection strategy runs in a separate, non-blocking thread. |
true |
Reconnect Forever
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Frequency |
Number |
How often in milliseconds to reconnect. |
||
blocking |
Boolean |
If false, the reconnection strategy runs in a separate, non-blocking thread. |
true |
Expiration Policy
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Max Idle Time |
Number |
A scalar time value for the maximum amount of time a dynamic configuration instance should be allowed to be idle before it’s considered eligible for expiration |
||
Time Unit |
Enumeration, one of:
|
A time unit that qualifies the Max idle time attribute. |
Local File Attributes
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Last Modified Time |
DateTime |
x |
||
Last Access Time |
DateTime |
x |
||
Creation Time |
DateTime |
x |
||
Size |
Number |
x |
||
Regular File |
Boolean |
false |
||
Directory |
Boolean |
false |
||
Symbolic Link |
Boolean |
false |
||
Path |
String |
x |
||
File Name |
String |
x |
Matcher
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Created Since |
DateTime |
Files created before this date are rejected. Any timezone specification in this value is ignored and the Mule server’s time zone is used instead. |
||
Created Until |
DateTime |
Files created after this date are rejected. Any timezone specification in this value is ignored and the Mule server’s time zone is used instead. |
||
Updated Since |
DateTime |
Files modified before this date are rejected. Any timezone specification in this value is ignored and the Mule server’s time zone is used instead. |
||
Updated Until |
DateTime |
Files modified after this date are rejected. Any timezone specification in this value is ignored and the Mule server’s time zone is used instead. |
||
Accessed Since |
DateTime |
Files that were last accessed before this date are rejected. Any timezone specification in this value is ignored and the Mule server’s time zone is used instead. |
||
Accessed Until |
DateTime |
Files that were last accessed after this date are rejected. Any timezone specification in this value is ignored and the Mule server’s time zone is used instead. |
||
Not Updated In The Last |
Number |
Minimum time that should pass since a file was last updated for it not to be rejected. This attribute works in tandem with Time unit. |
||
Updated In The Last |
Number |
Maximum time that should pass since a file was last updated for it not to be rejected. This attribute works in tandem with Time unit. |
||
Time Unit |
Enumeration, one of:
|
A Time unit that qualifies the Updated in the last and the Not updated in the last attributes. |
MILLISECONDS |
|
Filename Pattern |
String |
|||
Path Pattern |
String |
|||
Directories |
Enumeration, one of:
|
INCLUDE |
||
Regular Files |
Enumeration, one of:
|
INCLUDE |
||
Sym Links |
Enumeration, one of:
|
INCLUDE |
||
Min Size |
Number |
|||
Max Size |
Number |
Repeatable In Memory Stream
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Initial Buffer Size |
Number |
This is the amount of memory that will be allocated in order to consume the stream and provide random access to it. If the stream contains more data than fits into this buffer, then the buffer expands according to the Buffer size increment attribute, with an upper limit of the Max in memory size. |
||
Buffer Size Increment |
Number |
How much to expand the buffer size if it exceeds its initial size. Setting a value of zero or lower will mean that the buffer should not expand, meaning that a |
||
Max in Memory Size |
Number |
This is the maximum amount of memory to use. If more than the specified maximum is used, then a |
||
Buffer Unit |
Enumeration, one of:
|
The unit in which all these attributes are expressed |
Repeatable File Store Stream
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Max In Memory Size |
Number |
Defines the maximum memory that the stream should use to keep data in memory. If more than that is consumed then it will start to buffer the content on disk. |
||
Buffer Unit |
Enumeration, one of:
|
The unit in which Max in memory size is expressed |
Redelivery Policy
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Max Redelivery Count |
Number |
The maximum number of times a message can be redelivered and processed unsuccessfully before triggering |
||
Use Secure Hash |
Boolean |
Whether to use a secure hash algorithm to identify a redelivered message. |
||
Message Digest Algorithm |
String |
The secure hashing algorithm to use. If not set, the default is |
||
Id Expression |
String |
Defines one or more expressions to use to determine when a message has been redelivered. You can set this property only if Use secure hash is not selected. |
||
Object Store |
ObjectStore |
The object store where the redelivery counter for each message is stored. |
Repeatable In Memory Iterable
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Initial Buffer Size |
Number |
This is the amount of instances that will be initially be allowed to be kept in memory in order to consume the stream and provide random access to it. If the stream contains more data than fits into this buffer, then the buffer expands according to the Buffer size increment attribute, with an upper limit of Max in memory instances. Default value is 100 instances. |
||
Buffer Size Increment |
Number |
This is by how much the buffer size expands if it exceeds its initial size. Setting a value of zero or lower will mean that the buffer should not expand, meaning that a |
||
Max in Memory instances |
Number |
This is the maximum number of memory instances to use. If more than the specified maximum is used, then a |
Repeatable File Store Iterable
Field | Type | Description | Default Value | Required |
---|---|---|---|---|
Max In Memory Size |
Number |
This is the maximum amount of instances that will be kept in memory. If more than that is required, then it will start to buffer the content on disk. |
||
Buffer Unit |
Enumeration, one of:
|
The unit in which maxInMemorySize is expressed |
||
In Memory Objects |
Number |
Defines the maximum memory the stream uses to keep data in memory. If more than the specified memory is consumed, then the system starts to buffer the content on disk. |
500 |
Time Between Size Check Parameter Behavior
The Write operation on a file can take time to complete and get the file ready to read or access. Use the timeBetweenSizeCheck
parameter to prevent an operation from accessing an incomplete file.
When you set this parameter, it verifies the file’s size before accessing the file contents.
The verification validates that the file’s size does not vary after
waiting for the amount of time specified by the parameters timeBetweenSizeCheck
and timeBetweenSizeCheckUnit
.
The timeBetweenSizeCheck
parameter then indicates the time to wait between each
verification, which is performed twice. If the file’s size remains the same during both times, this assumes that the Write operation is complete and the access operation can continue, otherwise an exception is thrown.
The performed wait indicates that the thread executing
the operation goes to sleep for the indicated period of time. This wait occurs
at the moment of retrieving the content of the file. If the flow never accesses
the content of the file, the check is not performed.
In Mule runtime engine version 4.1 and 4.2, this wait can take place in multiple message processors, and the File Connector has no control over which thread is the one performing the wait. Any thread from any thread pool, even a CPU-intensive thread, which is not meant for this kind of task, can be the one performing the wait. |