Skip to Content
0
Mar 30, 2015 at 05:37 PM

ui5 image upload using oData

849 Views

Hello guys.

I got a simple ui5-oData CRUD which has the following:

a JS view
a JS controller

I'm able to choose a picture from my computer, but when I hit save button in my view it just goes null to the database. How can I properly get the image using my uploader component? Probably is not using getValue like the other fields. Any ideas.
I'm a newbie in ui5! Thanks in advance

My js view has the following ui5 component

var uploader = new sap.ui.unified.FileUploader(this.createId("uploader"),{
     id: "fileUploader",
            name: "myFileUpload",
            buttonOnly: true,
            uploadUrl: "upload/",
            tooltip: "Upload your file to the local server",
            fileType: ["jpg", "png"],
            uploadOnChange: true
         
  });


My controller has the following method

handleAcceptButtonPress: function(evt){
     var controller = this;
  var oModel = sap.ui.getCore().getModel();


  var jsonData = {
     "COMPANYDATAID": "0000000000",
  "COMPANYNAME": controller.byId("company-name-textfield").getValue(),
  "CORPORATENAME": controller.byId("corporate-name-textfield").getValue(),
  "PHONENUMBER": controller.byId("phone-number-textfield").getValue(),
  "CREATEDATE": null,
  "ADDRESS": controller.byId("address-textfield").getValue(),
  "SITE": controller.byId("cnpj-textfield").getValue(),
  "CNPJ": controller.byId("site-textfield").getValue(),
  "LOGO.LOGOID":controller.byId("uploader").getValue()
  };

  oModel.setHeaders({"content-type":"application/json;charset=utf-8"});
  oModel.create("/CompanyRegister", jsonData, null, function(oData, res){
  console.log("Partner creation successful");

  var oContext = oModel.createEntry("/CompanyRegister", oData);
  oContext.sPath = "/CompanyRegister("+oData.COMPANYDATAID+")";
  controller.nav.to("Detail", oContext);
  oModel.deleteCreatedEntry(oContext);
   
     controller.clearForm();
  }, function(err){
  alert("Partner creation failed");
  });
  },


Attachments

Untitled.png (11.2 kB)