Skip to Content

Hi All,

When we are uploading a image to the SAP using fileuploader, after the completion of selecting the file i wanted to display the image on the screen.

For displaying the image by using the local system file path not from the project.

For this please follow the procedure:

Create a project and give the title and the view name usually how we give in the same way,

I am using the JS views.

In the view.js write code for the file uploader as shown below

new sap.ui.unified.FileUploader(“myupload”,{

  

     placeholder:”Select Image”,

     uploadOnChange: true,

  

     uploadComplete:[oController,oController.uploadc]

  }),

After this we need to display the image the one which we selected,so

new sap.m.Image(“img”,{width:”200px”})

Here we are not giving the source to the image because we have to set this source after selecting the image in run time.

Now we have to write function for uploadComplete in the controller.js

uploadc:function(evt)

{

          var f = evt.oSource.oFileUpload.files[0];  //here we will get the file which we have been selected in to the variable f

            var path = URL.createObjectURL(f);     // here we are generating the URL based on the local file system and will pass the url in to path

              

          var img = sap.ui.getCore().byId(“img”); // we are getting the id of the image

            img.setSrc(path);  //we are setting the source of the path to the image to display the image

}

please find the screen shots respective to the code:

1.PNG2.PNG3.PNG4.PNG5.PNG

Hope this document will be helpful,

If there is any mistake please let me know…

Thanks,

Deepak Raj.

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