Skip to Content
Technical Articles
Author's profile photo Pierre Godart

SAP Cloud Application Programming Model (CAP): simple file upload service using node.js

Description of this post

SAP CAP is a powerful framework but it is not yet well documented and some features are not fully operational. This is not a problem since it relies on Node.js runtime… Indeed, Node.js is the event-driven JavaScript runtime that comes with a *lot* of libraries for everything you need thanks to the huge community of users/programmers.


Why a file upload service? Do we really need this? Yes and no.

You can use the media handling functionalities on an entity’s attribute… (CDS definition -> @Core.MediaType annotation) this can be done very quickly but you’ll get basically an upload service that will record the file content in your database…


I want to process the content of the file, use it for different entities’ feeding, correct errors, format some fields… this seems far more simple using a dedicated service build on my own via a node.js entry point.


Let’s begin…


Client side UI5 page elements

User interface:


Xml view: to upload a file, the “FileUploader” component is used, with this configuration:


Points of attention (that will be used on the server side later):

  • “Name” attribute => “UploadedFile”
  • uploadUrl => “/UploadFile”
  • httpRequestMethod => “POST”


Controllers: the most important handlers:



Server side layer

First let’s create the definition of the service… Since CAP is based on the “express” web framework, we need to add our own version of the “server.js” file in our application directory (“/srv” directory)…

I’ll use two libraries/additional packages to deal with the file upload and the file parsing (the file will be a simple CSV file):

=> In the “server.js” file:

  • const fileUpload    = require(‘express-fileupload’)
  • const Papa          = require(‘papaparse’)


Full content of the “server.js” file:



Point of interest:

Var sKeysOfEntity = Object.keys(BankOperationsBankIng.elements);

=> Extract attributes of the CDS entity to allow a mapping with the CSV file fields… (via “transformHeader” inline function)


That’s all!

Thanks for reading,

Kind regards,


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Minjie Lao
      Minjie Lao

      Hi Pierre,


      My question is a little bit out of this scenario, is that possible to upload the csv file directly on CDS layer?


      For ex: customer can use CAP model as inbound API process, to import their csv to my HANA table.


      Appreciated if you can share some thoughts

      Author's profile photo Sonal Sharma
      Sonal Sharma

      Hi Pierre,

      When the application is deployed to SAP BTP, when you press the upload button after selecting a CSV file, it gives 403 Forbidden error although the file gets uploaded successfully in the local environment. How did you fix this issue?

      Best regards,