Skip to Content
author's profile photo Former Member
Former Member

File Upload problem in SAP HANA UI5

Hello Expert,

I am trying to upload csv file data into HANA table. I created HANA XS project and created following Fileupload.view.js , Fileuploader.controller.js and BatchFileUpload.xsjs. Problem is that I'm getting 403 forbidden error when xsjs service executing.

Fileupload.view.js -



Fileuploder.controller.js

BatchFileUploader.xsjs

Error: 403 Forbidden error.

Please help me to get this resolve.

Thanks.

Shweta

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 03, 2015 at 02:33 PM

    Hi,

    Seems like the xcsrf token is not set in the header.

    Try something like this:

    var header_xcsrf_token = sap.ui.getCore().getModel().getSecurityToken();

    var oHeaders = {

    "x-csrf-token" : header_xcsrf_token,

    "slug" : file.name

    };

    jQuery

    .ajax({

    type : 'POST',

    url : "/sap/opu/odata/sap/ZC_CI_UPLOAD_SRV/thesises('"

    + sap.ui.getCore().byId(

    'masterSelect')

    .getSelectedKey()

    + "')/files",

    headers : oHeaders,

    ...

    Kind regards,

    RW

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Below is the approach that I tried and successfully able to upload.

      Step1: Extend FileUploader (sap.ui.unified.FileUploader)

      Overwrite the Upload method by AJAX call passing X-CSRF-Token

      jQuery.sap.declare("com.ODataFileUploader.Component");

      jQuery.sap.require("sap.ui.unified.FileUploader");

      sap.ui.unified.FileUploader.extend("com.ODataFileUploader.Component", {

      metadata : {

      properties : {

      "modelName" : "string",

      "slug" : "string",

      "csrf" : "string"

      }

      },

      upload : function() {

      var file = jQuery.sap.domById(this.getId() + "-fu").files[0];

      try {

      if (file) {

      this._bUploading = true;

      var that = this;

      var _handleSuccess = function(data, textStatus, jqXHR){

      that.fireUploadComplete({"response": "Success: File uploaded to entity" });

      that._bUploading = false;

      };

      var _handleError = function(data){

      var errorMsg = '';

      if (data.responseText[1]){

      errorMsg = /<message>(.*?)<\/message>/.exec(data.responseText)[1];

      }else{

      errorMsg = 'Something bad happened';

      }

      that.fireUploadComplete({"response": "Error: " + errorMsg});

      that._bUploading = false;

      };

      var oHeaders = {

      "x-csrf-token": this.mProperties.csrf,

      "slug": this.mProperties.slug,

      "X-Requested-With": "XMLHttpRequest",

      "Content-Type": file.type,

      "DataServiceVersion": "2.0",

      "Accept" : "text/plain, */*"

      };

      jQuery.ajax({

      type: 'POST',

      url: this.getUploadUrl(),

      headers: oHeaders,

      cache: false,

      contentType: file.type,

      dataType: "text",

      processData: false,

      data: file,

      success: _handleSuccess,

      error: _handleError

      });

      jQuery.sap.log.info("File uploading to " + this.getUploadUrl());

      }

      } catch(oException) {

      jQuery.sap.log.error("File upload failed:\n" + oException.message);

      }

      },

      renderer : {

      }

      });

  • Posted on Nov 06, 2015 at 08:32 AM

    Please go through below documents.

    1. Upload data
    2. File upload using SAPUI5 Control
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 18, 2016 at 04:01 AM

    I am developing in SAP UI5 ut i am facing a problem in the Collection upload control.

    I have not been able to push my image or document data into the database.It is showing the error of push property of undefined even if i have defined the variable.var file_Data = btoa(reader.result);
    var fileData = {
    "FILE_DATA" : file_data,
    "FILE_NAME" : file.name,
    "MIME_TYPE" : file.type,
    "SIZE" : file.size,
    "LAST_MODIFIED" : file.lastModifiedDate.toString().substring(0,15),
    "FILE_DESCRIPTION": sap.ui.getCore().byId('idInputFileDescription').getValue()
    };
    if(sap.ui.getCore().getModel('idModel').getData()){
    var aDocuments = sap.ui.getCore().getModel('idModel').getData().documents;
    var file_data = btoa(reader.result);
    ****aDocuments.push(file_Data);****
    sap.ui.getCore().getModel('idModel').setData({documents : aDocuments},true);
    sap.ui.getCore().byId('idDocumentsList').rerender();

    I am attaching the screenshot of the problem and code.

    Please provide me solution of problem.


    2.png (52.7 kB)
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.