Skip to Content
avatar image
Former Member

How to upload image using odata services in sapui5

I want to upload image using js view and controller with odata services

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jan 24, 2017 at 11:41 AM

    Hi Kallesh ,

    It depends on your backend upload service, what kind of data we need to POST.

    On UI5 side you just check out this example : https://sapui5.netweaver.ondemand.com/sdk/explored.html#/sample/sap.m.sample.UploadCollection/preview

    Just understand the different events of uploader like onChange you need to set headers of your post and on upload complete you need to refresh the model with new uploaded content

    thanks

    Viplove

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Kallesh ,

      If your backend service to upload the image is a form upload than you just need to call like below :

      var oFileUploader = sap.ui.getCore().byId("<id of the file uploader>"); // or this,getView().byId(" <id of the file uploader>" )

      oFileUploader.upload();

      // this will automatically uploads you selected file in the file uploader control. in the file uploader you need to specify the upload url

      And if you background service accepts bytes array string .. than you need to convert your image into byte array and than send them in the POST request.

      thanks

      Viplove