Hello,
XS users,
I'm trying to insert data into a table by importing a txt file.
but I can't get the file imported in the XSJS.
JS file using SAPUI5 FileUploader
var oFileUploader2 = new sap.ui.commons.FileUploader({ name: "upload2", uploadOnChange: false, uploadUrl: "../WebContent/vendas/ficheiros"}); layout2.createRow(oFileUploader2); // create a second button to trigger the upload var oTriggerButton = new sap.ui.commons.Button({ text:'Carregar', press: buttonPressed });
The buttonPress function is going to call our XSJS file
function buttonPressed(oControlEvent) { var jURL = '../WebContent/vendas/fileUploader.xsjs'; jQuery.ajax({ url:jURL, TYPE: 'POST' });
Now trying to get the file imported, i think that the problem it's that the body doesn't have the file
//create the query var query = 'insert into "SCHEMA"."TABLE" values(?,?,?,?,?)'; //catch the body if($.request.body){ data = $.request.body.asString(); } //open connection var conn = $.db.getConnection(); try{ var pstmt = conn.prepareStatement(query); var linhasInserir = data.split(/\r\n|\n/); var lines; var entries; var cells; pstmt.setBatchSize(linhasInserir.length); for (lines=0; lines<linhasInserir.length; lines++) { entries = linhasInserir[lines].split(';'); cells = entries.splice(0,5); pstmt.setString(1,cells[0]); pstmt.setString(2,cells[1]); pstmt.setString(3,cells[2]); pstmt.setString(4,cells[3]); pstmt.setString(5,cells[4]); pstmt.addBatch(); } pstmt.execute(); pstmt.close(); conn.commit(); conn.close();
Can anyone give some hit, how can we pass a file into the XSJS.
The code it´s working if I manualy set the data to be inserted
var data = [ "cell1;cell2;cell3;cell4;cell5","cell6;cell7;cell8;cell9:cell10"] the records will be well inserted into the hana table
thanks in advance,
Nuno Lopes