Skip to Content

Introduction:

In my previous blog we discussed about how to upload a file via SAP UI5 application and store it in MongoDB. In continuation with the same, we are going to discuss how to download the document from MongoDB using Nodejs and SAP UI5 code in this blog.

Assuming that you already have prerequisites as discussed earlier, we are going to concentrate on just the download functionality.

Step 1: Developing SAP UI5 screen

At the beginning we are going to create SAP UI5 screens (refer 1.1 view.xml and 1.2 controller.js)


  1.1 view.xml


1.2 controller.js

Our SAPUI5 screens are developed, now we will write Nodejs code.

Step 2: Logic in Nodejs to download document

As you can see in image 1.2 controller.js, we have a nodejs function i.e. “/downloadFiles”, now we are going to write the code for the given function.

Note: Don’t forget to start the MongoDB and Nodejs. (I have already explained procedure for how  to start MongoDB in my previous blog)


 2.1 Nodejs code

As per previous blog I have uploaded a PDF file named as ‘SAP UI.pdf’ which generated an Object Id as ‘585948f17e6eb67ee891b538’ (refer image 2.2 Robomongo Output)


2.2 Robomongo output

Here in Nodejs I have hardcoded value to fileid and filename but there are various ways to get Object Id and Filename from MongoDB.

Step 3: Downloading document

We are done. Now we are going download the document by just clicking on link.


3.1 Final output

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply