[aXes 4.1.0] Upload a file to the IFS using Longreach in aXes

Use this Forum to post tips and techniques for using aXes. Please explain in detail. This Forum is managed by the aXes user community. LANSA cannot guarantee the accuracy of any information posted to this Forum.

Moderator: jeanmichel

Post Reply
User avatar
Posts: 88
Joined: 23 May 2014, 11:37
Location: Sydney

[aXes 4.1.0] Upload a file to the IFS using Longreach in aXes

Post by jeanmichel » 05 Sep 2017, 18:16

This tip explains how to use LongReach which is included in aXes 4.1.0 to upload a file onto the IFS.

This tip assumes you have installed aXes with the default values. If this is not the case, please adjust with your settings.

1) Make sure the IBMi Services (JSM) features are configured properly. For this check the following.

a) Make sure the subsystem AXES410JSM is running on your IBMi. Check WRKACTJOB for AXES410JSM

b) Make sure the IBMi Services (JSM) features is working by using the data explorer feature on the axes homepage.
axeshome1.png (61.94 KiB) Viewed 1518 times
If all is well configured you should see the login screen below. The login page for Data Explorer. If you get any messages, there is problem and this needs to be fixed first.
DE1.png (34.19 KiB) Viewed 1518 times

2) Navigate to your IFS folder IFS://axes410jsm/jsm/instance/system and open the file httpd.xml

a) Check the port under which the services are running. For this check around line 20 for <listen port=XXXX ...
httpd1.png (34.24 KiB) Viewed 1515 times
b) Check that the services are working correctly by using the IBMi services port above http://yourserver:port.
httpd2.png (12.01 KiB) Viewed 1515 times
c) Back to you httpd.xml file. Locate the the following property LongReach around line 215. Add the line under remote service activation to allow XSS:
<parameter name="service.origin" value="*"/>
httpd3.png (53.96 KiB) Viewed 1515 times
d) Make sure the section All non-public users is uncommented as shown below. That is no <!-- -->. Note the value of the base folder (highlighted in yellow.
httpd4.png (77.8 KiB) Viewed 1515 times
In our case the base folder is located at /longreach/user/{NAME}. Hence if you login to your server with USER1 the base folder will be at /longreach/user/USER1. You can change this folder as you wish.

e) Restart the SBS AXES410JSM on the IBMi.

3) We can now start designing our axes project to use this functionality.

a) Create a new project in aXes 410. Login to your IBMi using you project in the aXes developer tools.

b) First step is to add a file input field which will allow the selection of a files from the local computer. For this add a Multitype Input Box.
axdevjsm1.png (74.64 KiB) Viewed 1515 times
c) Set the following properties for the Multitype Input box (in yellow)
axdevjsm2.png (22.6 KiB) Viewed 1515 times
d) Now drag and drop a Push Button. Set the following script in the onClick event. Call you button "put file"

Code: Select all

//add this to load the necessary JS library. Note user the IBMi services port and your server address. In our case it is LANSA14:8413

// the host JSON variable is used to define the server to which the request is going to. Use your server name with the IBMi services port again.
// Also fille in the IBMi Username allowed to access the server.
var m_host = { endpoint:"http://lansa14.syd.lansa.com.au:8413/service/longreach.jsp", profile:"ADMDEV", password:"xxxxx" } ;


function putFile ()
        //this is the call back function after the JSm call has returned.
        function callback ( response )
            console.timeEnd ( "put file" ) ;

            alert ( JSON.stringify ( response ) ) ;

            console.time ( "put file" ) ;

            // This is where you get the data from your file input. GETFILES is an aXes API which returns the files from the 
            // Mutitype Input Box File selection as an array. We only use the first file at position 0.
            var file_array = GETFILES( 'id-file1' );
            var file = file_array[0]; 

            if ( !file )
                alert ( "Choose a file" ) ;

                return ;

            // Read file asynchronous

            var reader = new FileReader() ;

            reader.onloadend = function ( event )
                if ( !reader.result ) // ArrayBuffer
                    alert ( "No read file result" ) ;

                    return ;

                console.log ( "reader result length " + reader.result.byteLength ) ;

                if ( reader.result.byteLength > 1000000 )


                    Note: the reader.result will be encrypted, because Uint8Array uses the underlying ArrayBuffer.

                // Using asynchronous callback mode the file is sent to the server. Note the user of {BASE} define in the httpd.xml file

                LUICONNECTOR.putFile ( m_host, { path:"{BASE}/docs", name:file.name }, callback, new Uint8Array( reader.result, 0, reader.result.byteLength ) ) ;

            reader.readAsArrayBuffer( file ) ;
        catch ( e )
            alert ( "putFile exception " + e ) ;

Your screen should look like that:
axdevjsm3.png (94.73 KiB) Viewed 1515 times
4) Try your code.

a) Save your customisations and reload your project.

b) Pick a file on your computer

c) Click the put file button. You should see the following.
axdevjsm4.png (104.3 KiB) Viewed 1510 times
d) Open your IBMi and navigate to your {BASE} folder
axdevjsm5.png (41.46 KiB) Viewed 1510 times

Jean-Michel Rapin

email: JeanMichel.Rapin@lansa.com.au
Address: 122 Arthur Street, North Sydney, NSW 2060, Australia
Tel: +61 289 070 262 http://www.lansa.com | http://blog.lansa.com |

Posts: 29
Joined: 24 Jul 2017, 17:02

Re: [aXes 4.1.0] Upload a file to the IFS using Longreach in aXes

Post by Fairdinkum » 01 Jun 2018, 11:10


This is an another example using Longreach in aXes v4.1.0.

See the video here:
https://drive.google.com/open?id=1CW-QF ... HwBUkDkHsc

The sample aXes project is here:
https://drive.google.com/open?id=1d5y7z ... ntuUrmfyRD
This save file contains the aXes project which video shows.
*Target Release is V7R1M0.

HTH. :)

Best Regards,
Hidekazu Tanaka

Post Reply