Skip to Content
Technical Articles
Author's profile photo Upender Reddy Dareddy

How to upload the images with zoom functionality in SAPUI5

Hi All,

Today In this blog post, I am going to explain how to upload the images and showing uploaded  images with zoom functionalities.

Let’s see how this can be achieved.

First, we need to login to the SAP Cloud Platform. After login, We have to create a new  project in SAP Web IDE.

Here we are creating a project with a project name “UploadImages” as shown below.


Now lets create an empty JSON structure as shown below.


	"Images": [



Later we can use this model to store the file content of uploaded images, so that we can bind those images to the view.


<mvc:View controllerName="com.UploadImages.controller.View1" xmlns:core="sap.ui.core" xmlns:f="sap.ui.layout.form"
	xmlns:html="" xmlns:l="sap.ui.layout" xmlns:mvc="sap.ui.core.mvc" xmlns:u="sap.ui.unified" xmlns="sap.m">
	<Shell id="shell">
		<App id="app">
				<Page id="page" title="Upload Images">
						<u:FileUploader change="onUploadPress"  id="fileUploader"
							name="ImagesUpload" buttonOnly="true" buttonText="Browse"/>
						<l:Grid class="sapUiMediumMarginTop" content="{imagesModel>/Images}" defaultSpan="L3 M4 S12" id="imageGrid" vSpacing="0.5">
							<VBox height="">
									<l:GridData span="L3 M6 S12"/>
								<Image class="imgclass" height="135px" id="gridImagesId" press="onImageZoom" src="{imagesModel>Pic}" width="95%"></Image>
									content='&lt;div id="myModal" class="modal"&gt; &lt;span class="close"&gt;X&lt;/span&gt;&lt;img class="modal-content" id="img01"/&gt;&lt;div id="caption"&gt;&lt;/div&gt;&lt;/div&gt;'></core:HTML>


View1.controller.js : 

], function (Controller,JSONModel) {
	"use strict";

	return Controller.extend("com.UploadImages.controller.View1", {
		onInit: function () {
                       /* load images json structure using jQuery modulepath */
			var oModel = new JSONModel("com.UploadImages", "/model/images.json"));
			this.getView().setModel(oModel, "imagesModel");

Image Upload:

The below function will be triggered whenever user clicks on “Browse” button.

onUploadPress: function(oEvent) {

			var oModel = this.getView().getModel("imagesModel");
			var oData = oModel.getData();
				var f = oEvent.oSource.oFileUpload.files[0];
				var Path = URL.createObjectURL(f); 
				var obj = {
					"Pic": Path

Once the file has been uploaded, we are updating images.json structure with the corresponding image name and its source path.

ZOOM Functionality:

This function will trigger whenever user clicks on anyone of the uploaded image.

	onImageZoom: function(oEventArgs) {

			var ImagePath = oEventArgs.getSource();
			var sourecepath = ImagePath.getSrc();
			var modal = document.getElementById("myModal");  // pass model id
			var modalImg = document.getElementById("img01");  //pass image id = "block";
			modalImg.src = sourecepath;
			modalImg.height = 500;
			modalImg.width = 100;
			var span = document.getElementsByClassName("close")[0];
			span.onclick = function() { = "none";


We can control the modal resolution by its height and width.


The below CSS is used for zooming in the image,

	 background-color: rgb(66, 179, 244) !important;
margin-left:330px !important;	
.imgclass {
  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
  border: 2.5px solid black;

.imgclass:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.9); /* Black w/ opacity */

/* Modal Content (image) */
.modal-content {
  margin: auto;
  display: block;
  width: 95%; 

/* Add Animation */
.modal-content, #caption {  
  -webkit-animation-name: zoom;
  -webkit-animation-duration: 0.6s;
  animation-name: zoom;
  animation-duration: 0.6s;

@-webkit-keyframes zoom {
  from {-webkit-transform:scale(0)} 
  to {-webkit-transform:scale(1)}

@keyframes zoom {
  from {transform:scale(0)} 
  to {transform:scale(1)}

/* The Close Button */
.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #FF0000;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;

.close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
  .modal-content {
    width: 100%;

The output as follows:

Now we can see the all uploaded images in a gallery mode. This is how it looks like after uploading the images as shown below

In the above gallery we have 3 images. suppose lets say we want see the second image with zoom effects whenever user clicks on it.

This is how we gonna display.

@image source : Rebekka D NickyPe

Conclusion:  By following the above approach we have successfully uploaded the images and we are able to show that particular image with zoom effects.


Thanks for Reading

Assigned Tags

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


      Why just don`t use sap.m.LightBox control instead sap.m.Image? You can find zoom functionality in that control.

      Author's profile photo Upender Reddy Dareddy
      Upender Reddy Dareddy
      Blog Post Author


      We implemented this functionality in the older version (1.32.7).

      Author's profile photo Prasanna Venkatesh Rao S
      Prasanna Venkatesh Rao S

      I want this full source code can you share with me. I am new to sapUi5

      Author's profile photo Jerry Janda
      Jerry Janda

      Inclusion of a personal email address violates the community's rules of engagement. I have removed. Please learn more at:

      Kind regards,