Using File Connector with a JSON Payload

Isuru Uyanage
Think Integration
Published in
3 min readJan 27, 2020

In this scenario, we will look into how to use WSO2 File Connector with a REST API and run it via the Micro Integrator.

Assume we want to copy a file from one location to another location.

In order to create the API resource, we use WSO2 Integration Studio.

Create an ESB Solution Project. You can further refer to this document.

Please follow the full source below. I have written two API resources in order to copy a file and delete a file.

URL copy: http://localhost:8290/filecon/copy

URL delete: http://localhost:8290/filecon/delete

Copy Operation

Here I’m sending the sourceURL and destinationURL via a JSON Payload while invoking the API. It will be read through a property mediator. It would be referenced in the File Connector.

Delete Operation

In the delete operation, only the source is sent though which is the path where the file which we want to delete exists.

Running in the Micro Integrator

Right-click on the Composite Application Project and click on ‘Export Project Artifacts and Run’. Select ‘Run on Micro Integrator’.

Micro Integrator will be started and the carbon application will be deployed. You can further refer to the application deployed through the CLI tool.

Make sure you first export the PATH as below.

$ export PATH=/path/to/mi/cli/directory/bin:$PATH

Then login.

./mi remote login

Provide default credentials admin for both username and password.

In order to view the APIs deployed, execute the following command.

./mi api show

It will display the URL.

Invoke the copy operation as below. It can be used Postman to invoke the API.

Resource: POSTURL: http://localhost:8290/filecon/copy

Payload

If the File is copied, you will get the success response.

Invoke the Delete operation as below.

--

--