[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
jeanmichel
Posts: 100
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
axeshome1.png (61.94 KiB) Viewed 2153 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
DE1.png (34.19 KiB) Viewed 2153 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
httpd1.png (34.24 KiB) Viewed 2150 times
b) Check that the services are working correctly by using the IBMi services port above http://yourserver:port.
httpd2.png
httpd2.png (12.01 KiB) Viewed 2150 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
httpd3.png (53.96 KiB) Viewed 2150 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
httpd4.png (77.8 KiB) Viewed 2150 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
axdevjsm1.png (74.64 KiB) Viewed 2150 times
c) Set the following properties for the Multitype Input box (in yellow)
axdevjsm2.png
axdevjsm2.png (22.6 KiB) Viewed 2150 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
$.getScript("http://lansa14.syd.lansa.com.au:8413/axes/lui-encrypt-min.js");
$.getScript("http://lansa14.syd.lansa.com.au:8413/axes/lui-connector-min.js");

// 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" } ;

putFile();

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 ) ) ;
        }

        try
        {
            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
axdevjsm3.png (94.73 KiB) Viewed 2150 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
axdevjsm4.png (104.3 KiB) Viewed 2145 times
d) Open your IBMi and navigate to your {BASE} folder
axdevjsm5.png
axdevjsm5.png (41.46 KiB) Viewed 2145 times
END
Regards,

Jean-Michel Rapin

LANSA Pty Ltd
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 |

Fairdinkum
Posts: 42
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

Hi,

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

Joerg Hamacher
Posts: 23
Joined: 09 Mar 2016, 00:29

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

Post by Joerg Hamacher » 02 Jul 2019, 22:32

Hi,

I tried Hidehaku's examples (great work, thank you very much) and succeeded in uploading the image file to IFS.
But the image is not displayed - only noimage.jpg

imageName is "A000090.jpg?0.29823732...."
imagePath is "longreachdata/shared/simpleupload/" (which is exactly the folder in which the image is saved"

What am I doing wrong?

Many thanks in advance,
Joerg

Fairdinkum
Posts: 42
Joined: 24 Jul 2017, 17:02

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

Post by Fairdinkum » 12 Jul 2019, 09:37

Hi Joerg,

Great to hear what you have succeeded in you aXes project.

I would like to suggest:
1) make sure the image file's data authority of *PUBLIC user. It should be *R or *RW.
2) imagePath probably should start with "/" this case.
3) make sure longreachdata folder is under the document root ( e.g. /axes/longreachdata).
4) if longreachdata folder is not under document root folder, you may be able to use URL Mapping directive in aXesW3.conf. It allows you to refer objects which in not located under document root folder.

HTH.

Hidekazu Tanaka

Post Reply