Skip to Content

How to move uploaded file to folder instead of inserting to the HANA database as Blob?

Hi Experts,

I am building a SAPUI5 app which requires a user to upload files on a weekly and in some instances on a daily basis. The total number of users is between 280-300 and each will be required to upload a file depending on the kind of data they are submitting. In most of the cases a user will be required to submit more than one file at a go.

I would like to save the file name into the database and the file to a folder.

I have used xsjs to insert data to HANA and would like to use sap.m.UploadCollection to view the different files.

The code I have used is as below.

var conn = $.db.getConnection();
         // var filename = $.request.parameters.get("file_name");
         // var fileBody = $.request.entities[0].body.asArrayBuffer();
         // $.response.setBody(fileBody);
          
          try {
        	  
        	  if ($.request.entities.length > 0) {


        	  var filename = $.request.parameters.get("file_name");
        	  var fileBody = $.request.entities[0].body.asString();
        	  //fileBody.move('/path/to/uploads');
        	  var pstmt = conn.prepareStatement( "INSERT INTO SCHEMA.IMAGE_STORE (USERID,AVATAR) VALUES(?,?)" );


        	  pstmt.setString(1,filename);  
        	  pstmt.setString(2,fileBody);
        	  $.response.contentType = 'text/plain';
        	  $.response.setBody("[200]:Upload for file " + filename + " was successful!");
        	  
        	  pstmt.execute();  
        	  conn.commit();
        	  fileBody.Move("path/to/our/uploads");
        	  }


        	} catch (e) {
        		$.response.contentType = 'text/plain';
        	    $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
        	    $.response.setBody("Failed: "+e.message);
        	}

I have tried the Move() method and it doesn't work. I have checked the File API and am not sure how I should use it.

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

0 Answers