SAP HANA XS File upload with UI5 -


i'm trying implement file upload in ui5 application on hana xs server. can't find many informations how - got idea?

here's simple implementation of plain text file upload:

client side js:

doupload: function() {     var uploadfield = document.getelementbyid("uluploader1-fu");     var file = uploadfield.files[0];      var reader = new filereader();     reader.onload = function (event) {     var source = event.target.result; // binary values     var name = file.name;            $.ajax({         url: "/services/upload.xsjs?cmd=import",         type: "put",         processdata: false,         contenttype: file.type,         data: source,         xhr: function() {             var req = $.ajaxsettings.xhr();             if (req) {                 if (req.overridemimetype) {                     req.overridemimetype('text/plain; charset=x-user-defined');                 }                 if (req.sendasbinary) {                     req.send = req.sendasbinary;                 }             }             return req;         },         error: function(xhr, textstatus, errorthrown){             alert(xhr.responsetext);         },         success: function() {             reader.onload = null;         }         });     };     reader.readastext(file); } 

and here's serverside xsjs service:

    function doimport() {     var data = '', conn = $.db.getconnection(), pstmt;        if($.request.body){         data = $.request.body.asstring();          }      var conn = $.db.getconnection();     var pstmt = conn.preparestatement( 'insert "test"."upload" (id, mimetype, data) values(?,?,?)' );      pstmt.setinteger(1,1);     pstmt.setstring(2,"text/plain");     pstmt.setstring(3,data);      pstmt.execute();     pstmt.close();      conn.commit();     conn.close();      doresponse(200,'');      $.response.contenttype = 'text/plain';     $.response.setbody('upload ok');     $.response.status = 200; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -