Mule - Delete files with Files Connector

3.2k views Asked by At

This is my main mule flow:

HTTP > Payload > File (Create) > Property (File Name) JMS

And that JMS calls to other flow that starts with JMS

JMS > JSON TO XML > File (Delete by file name)

Firstly, I create a file with the JSON message.

And finally, when JSON message is transformed to XML, I try to delete the file by name calling a property that tell me the name.

But the files doesn't delete. Its output this action by log:

Writing file to: C:\errors\91fa03a0-dd33-11e5-a0d9-408d5c4c1bf3.dat

How can I do to delete it?

I tried with the option autoDelete in the Connector Configuration but it doesn't delete.

<file:connector name="File1" outputPattern="#[message.inboundProperties.fileName]" autoDelete="true" streaming="false" validateConnections="true" doc:name="File"/>
1

There are 1 answers

0
JoostD On BEST ANSWER

You can't use this file outbound endpoint to delete a file.

If you would use something like S3 for example you can, but those connectors are 'operation-based'.

It's meant to write an new file or append data to an existing one.

The autoDelete option is for deleting the file once it has been read by a file inbound endpoint.

More info: https://docs.mulesoft.com/mule-user-guide/v/3.7/file-transport-reference

If you want to delete and for your usecase you should use a piece of JAVA code and use methods from the File Class: https://docs.oracle.com/javase/7/docs/api/java/io/File.html