Skip to Content
Technical Articles
Author's profile photo Wouter Lemaire

How to use the Document Repository Service in your UI5 app


I used the Document Repository Service in the FaceRecognition app:

During the developments of this app, I never new if the upload of an image was succefull or not. There is no visual tool to validate this. Therefore, I created the “Document Repository Viewer”. It’s a very small UI5 app to view what’s in your Document Repository:

The code in this app is simple but it was hard to get there. There is not much documentation on how to implement this in a UI5 app. The only thing I found was this:

A basic html page that show a list of documents and an upload function. But how to delete an image? And what if you want to upload a document via a custom http ajax request instead of a generated form request?

Therefore, I will share and explain the code that I’ve used behind the “Document Repository Viewer”.

I’m going to start from the beginning, from enabling to Document Repository Service till explaining the UI5 code. Just for the completeness of the blog post so everyone will be able to try it:

  • Activate the Document Repository Service
  • Install the Proxy Bridge
  • Destination
  • UI5 Code
Compared to the blog of Sharaha K, I’m only using the Proxy Bridge:


Activate the Document Repository Service

Activate the Document Service in you SCP account:

Go to Services and search for Document Service. This should be enabled by default, otherwise you need to enable it yourself.

Once it’s active (normally this is active by default), you’ll can open it directly from “Document Repositories”:

Create a repository:

And fill in all the details. Note down the Repository Key, you’ll need it later:

Install the Proxy Bridge

Build a Proxy Bridge like explained in SAP Help:

Deploy this Proxy Bridge on your SCP account by using the Eclipse tools or directly in the SCP Cockpit:


Create a destination to access the proxy bridge in the UI5 app in SCP and SAP Web IDE.






Description=Connection to Proxy Bridge App Wouter Lemaire



UI5 code


Start with a UI5 template in SAP Web IDE. I started with the basic template but any other will also work:

Add the configuration to the destination to the “neo-app.json”:

      "path": "/cmisproxysap",
      "target": {
        "type": "destination",
        "name": "documentservicewl",
        "entryPath": "/cmisproxysap"
      "description": "CMIS Connection Document Service"


In case you are using a different name for the destination, then you need to change the property “name”.

For all my http requests to the Proxy Bridge I’m using “XMLHttpRequest” which I wrapped into promises. This is very generic and done in the UI5 object “HTTPService”. I’m not going to explain in detail but you can always look at the code here:

This generic HTTPService is being used by the object RepoService, which is a short name for Repository Service. In the RepoService are all the requests related to the Repository Document Service:

Get repository id

Before we can read the data from the repository or do anything else, we need the repository id. This id is needed for any action on the repository because it’s part of the root url.

To know this, you open the Proxy Bridge and add the following


Like this:

This will give you all the details of your repository:

This should be dynamic in the app, so it shouldn’t be changed for every new repository. Therefore, I’ve added the following two functions in the RepoService:

getRepoId: function () {
	if (this.RepoId) {
		return Promise.resolve(this.RepoId);
	return this.getRepoInfo().then(function (info) {
		for (var field in info) {
			this.ReposId = info[field].repositoryId;
		return this.ReposId;
getRepoInfo: function () {
	return this.http("/cmisproxysap/cmis/json").get();

“getRepoInfo” will get all the information of the repository. The “getRepoId” will use “getRepoInfo” but only returns the Repository id and store it in RepoService. This will avoid that the app will need to fetch this id again for each action. The Repository id normally doesn’t change.

Reading all the documents

Reading all the files from the Repository Document service was the easiest one. This is just a HTTP GET request to the root of the repository. You only need to know the root url to the repository…

The root url exists out of the same part as the repository information together with the repository id followed by root:


In the RepositoryService, there is a function getFiles which will first get the repository id and use this id to get all the files on root level. This will give a list of all files.

getFiles: function () {
	return this.getRepoId().then(function (ReposId) {
		return this.http("/cmisproxysap/cmis/json/" + ReposId + "/root/").get();

Upload document

The upload function is based on the example html snippet from the documentation. This is now converted to pass all the properties as formdata in an HTTP Ajax request instead of via a form submit action.

The uploaded file object is wrapped into a FormData object together with some other properties:

  • Cmisaction: defines what you what to do, we want to create a new document -> “createDocument”
  • Objecttypeid: the type that it needs to create, can be document or folder
  • Name: the name of the file.

This formdata can then be posted to the same path as for reading all the documents. Again, this needs the repository id and will use the getRepoId function. (this function will cache the repositoryid and won’t send the request twice but use the cached id instead)


uploadFile: function (file) {
	var form = new FormData();
	form.append("datafile", file);
	form.append("cmisaction", "createDocument");
	form.append("propertyId[0]", "cmis:objectTypeId");
	form.append("propertyValue[0]", "cmis:document");
	form.append("propertyId[1]", "cmis:name");
	return this.getRepoId().then(function (ReposId) {
		return this.http("/cmisproxysap/cmis/json/"+ReposId+"/root").post(false, form);


Delete document

This one is probably the easiest, but it was the hardest to find!  Deleting a document requires the full path to that document with the cmisaction delete. Finding the action “delete” took me a lot of time. In the cmis documentation I found the action “deleteDocument”. Delete was just a lucky guess ?

Again, this needs the repository id.

deleteFile: function (name) {
	var form = new FormData();
	form.append("cmisaction", "delete");
	return this.getRepoId().then(function (ReposId) {
		return this.http("/cmisproxysap/cmis/json/"+ReposId+"/root/" + name).post(false, form);


Now, this RepoService is ready to use in the controller. Define the RepoService at the top of the controller and start using it.

Load the files and convert them to the format that you like: (The Document Repository Service uses property names that are not easy to use in your UI5 bindings. Therefor, I converted them to something that’s easier to understand and use.)

var result = await RepoService.getFiles();
var files = => ({
	isImage:["cmis:contentStreamMimeType"].value.indexOf("image") > -1 ? true : false
this.getView().setModel(new JSONModel({
	files: files
}), "repo");
return files;

Upload the file and update the list so the newly uploaded file will show up:

var file = oEvent.getParameter("files")[0];
// RepoService.uploadFile(file).then(() => this.loadFiles());
await RepoService.uploadFile(file);
await this.loadFiles();

Same for delete:

//RepoService.deleteFile(oEvent.getSource().getBindingContext("repo").getProperty("name")).then(() => this.loadFiles());
await RepoService.deleteFile(oEvent.getSource().getBindingContext("repo").getProperty("name"));
await this.loadFiles();

In the code examples in the controller I used Async and Await but also with arrow functions in comment. In both cases you’ll need to change it to “old school JS” or use a transpiler.

You’re ready to use the RepoService in your own project!

The full code example is available on GitHub:


Kr, Wouter

Assigned Tags

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

      Thank you so much, your tutorial is very useful.

      Author's profile photo adeete rajeev kumar
      adeete rajeev kumar


      Can you tell me how can i change permissions of certain users to read, write, delete a file.For example - user 1 can do all activites but user2 can just read the file


      Author's profile photo Manoj Kumar
      Manoj Kumar

      Document service integrated Sapui5 application.Once upload any file through document repository in browser network tab End user accessing and seeing data and downloaded image also.pls help me how to restrict on document service.

      Anything I need to add on Java application for document service.

      Thanks and Regards,

      Manoj kumar​