Skip to Content
avatar image
Former Member

How to upload files to HANA table using XSJS application

Hi Experts ,

I am developing a sap ui5 application where i need to upload image/pdf files.

I am using file uploader control ,but couldn't able to pass the file contents to the XS application.

View Code :

<u:FileUploader id="fileUploader" name="myFileUpload" uploadUrl="" width="400px" tooltip="Upload your file to the local server"
                <Button text="Upload File" press="handleUploadPress"/>

Controller Code

  handleUploadPress: function(oEvent) {
       var fileLoader = this.getView().byId("fileUploader");
       var fileName = fileLoader.getValue();"sap.ui.commons.MessageBox");
       if (fileName === "") {
"Please choose File.", sap.ui.commons.MessageBox.Icon.INFORMATION, "Information");
        } else {
          var uploadUrl = "/equip/oDataService/uploadFile.xsjs?filename=" + fileName;
          var file = + "-fu").files[0];
                 url: uploadUrl,
                 type: "GET",
                  beforeSend: function(xhr) {
                     xhr.setRequestHeader("X-CSRF-Token", "Fetch");
                  success: function(data, textStatus, XMLHttpRequest) {
                      var token = XMLHttpRequest.getResponseHeader('X-CSRF-Token');
                            url: uploadUrl,
                            type: "POST",
                            processData: false,
                            contentType: false,
                            data: file,
                            beforeSend: function(xhr) {
                               xhr.setRequestHeader("X-CSRF-Token", token);
                            success: function(data, textStatus, XMLHttpRequest) {
                              var resptext = XMLHttpRequest.responseText;
                 , sap.ui.commons.MessageBox.Icon.INFORMATION, "Information");

                            error: function(data, textStatus, XMLHttpRequest) {
                      "File could not be uploaded.", sap.ui.commons.MessageBox.Icon.ERROR, "Error");

XSJS Application code

try {

    var fileName = $.request.parameters.get("filename");

} catch (e) {
    $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
var output = {}; = [];

try {
    var conn = $.db.getConnection();

    var pstmt = conn.prepareStatement(

    if ($.request.entities.length > 0) {

        var logID = 3;

        logID = parseInt(logID);

        //  Read in the posted image or binary data as an Array Buffer - you can use this to save as a BLOB
        var fileBody = $.request.entities[0].body.asArrayBuffer();

        pstmt.setInteger(1, logID);
        pstmt.setBlob(2, fileBody); // Set the Blob as the array buffer that has the image data
        pstmt.setString(2, fileName);


        var record = [];

        $.response.contentType = "text/html";
        $.response.setBody("[200]:Upload for file" + fileName + " was successful!");

    } else {
        $.response.setBody("No Entries in request");

} catch (e) {
    $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
Add comment
10|10000 characters needed characters exceeded

  • Former Member


    I am trying figure this out. Have you finally find the problem of this implementation?

    Thank you in advance!


  • Hi,

    How have you been able to pass relative URL of the xsjs file in UI5 application.

    var uploadUrl ="/equip/oDataService/uploadFile.xsjs?filename=" + fileName;

    Can you provide some details as how this url gets converted to the absolute URL of xsjs file.



  • Follow
  • Get RSS Feed

1 Answer

  • Apr 26, 2018 at 02:19 PM

    there are a few blogs out there for image upload -- here is oine

    as far as pdf.. im not sure if you can upload one the same way.. most likely you have to post it tere

    Add comment
    10|10000 characters needed characters exceeded