Skip to Content

sap webide sapui5 upload file

hi,

I am beginner in SAPUI5 working in SAP WebIDE trial account.

I need help to make a simple application - upload an image from desktop using browse button

display the image on the screen.

Kindly help me with the tutorials/basics/example code/steps.

I am searching online and getting myriad of results. I am trying this right now, just to start with -

http://www.planetofbits.com/sap-ui5/sapui5-hello-world-first-sapui5-application/

but I am not able to achieve my requirement.

thanks for your inputs

bhakti.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • May 14 at 06:29 AM

    Hello Bhakti joshi

    Add a file uppload button in your view (Not tested code, just coppied code may be some smal buggs)

    <mvc:View xmlns:u="sap.ui.unified" xmlns:mvc="sap.ui.core.mvc" xmlns:t="sap.ui.table">
    <!-- File upploader --> 
    <u:FileUploader buttonText="Choose a file" id="fileUploader" change="onAddAttachment"></u:FileUploader>
    <!-- Image holder -->
    <Image src="{url>/url}"> </mvc:View>

    Add the onAddAttachment in yore controller

    onAddAttachment: function(oEvent) {
    //Get the file upploader field var oFileUploader = this.getView().byId("fileUploader");
    //Get the path of the file attached to the fileupploader var path = URL.createObjectURL(oEvent.getSource().oFileUpload.files[0]);
    //Get the file var file = jQuery.sap.domById(oFileUploader.getId() + "-fu").files[0];
    //Bind the url to a model to show it in the view. this.getView().setModel(new sap.ui.model.json.JSONModel({ url: path }), "url") },
    Add comment
    10|10000 characters needed characters exceeded