SAPUI 5 fileuploder controller function getFocusDomRef not working sometime












0















This seems to be weird error. :)



I am using the SAPIU5 fileuploder controller, it seems to be working fine. But sometimes the function getFocusDomRef is not able to fetch the parameters.



One more strange behaviour is that, it is working in Mac (chrome) without any issues but with Windows (chrome) it fails sometimes.



Using chrome Version 70.0.3538.102



Below is the code snippet:



 <u:FileUploader id="fileUploader" name="myFileUpload" fileType="csv" uploadComplete="handleUploadComplete" typeMissmatch="checkTypeMissmatch" fileAllowed="fileTypeAllowed" />




Controller:



handleUploadComplete() =>
var loFileUploader = sap.ui.getCore().byId("fileUploader");
loFileUploader.setValueState(sap.ui.core.ValueState.None);
var Title = sap.ui.getCore().byId("importCollectionTitle").getValue();

var domRefFile = loFileUploader.getFocusDomRef(); //The Buggy boy

var file = domRefFile.files[0];
var reader = new FileReader();

reader.onload = function(evt) {

var postXMLUploadFile = evt.target.result.trim().replace(/r/g, "");
var rows = postXMLUploadFile.split("n");

//Import CSV file data

};
reader.readAsText(file);









share|improve this question





























    0















    This seems to be weird error. :)



    I am using the SAPIU5 fileuploder controller, it seems to be working fine. But sometimes the function getFocusDomRef is not able to fetch the parameters.



    One more strange behaviour is that, it is working in Mac (chrome) without any issues but with Windows (chrome) it fails sometimes.



    Using chrome Version 70.0.3538.102



    Below is the code snippet:



     <u:FileUploader id="fileUploader" name="myFileUpload" fileType="csv" uploadComplete="handleUploadComplete" typeMissmatch="checkTypeMissmatch" fileAllowed="fileTypeAllowed" />




    Controller:



    handleUploadComplete() =>
    var loFileUploader = sap.ui.getCore().byId("fileUploader");
    loFileUploader.setValueState(sap.ui.core.ValueState.None);
    var Title = sap.ui.getCore().byId("importCollectionTitle").getValue();

    var domRefFile = loFileUploader.getFocusDomRef(); //The Buggy boy

    var file = domRefFile.files[0];
    var reader = new FileReader();

    reader.onload = function(evt) {

    var postXMLUploadFile = evt.target.result.trim().replace(/r/g, "");
    var rows = postXMLUploadFile.split("n");

    //Import CSV file data

    };
    reader.readAsText(file);









    share|improve this question



























      0












      0








      0








      This seems to be weird error. :)



      I am using the SAPIU5 fileuploder controller, it seems to be working fine. But sometimes the function getFocusDomRef is not able to fetch the parameters.



      One more strange behaviour is that, it is working in Mac (chrome) without any issues but with Windows (chrome) it fails sometimes.



      Using chrome Version 70.0.3538.102



      Below is the code snippet:



       <u:FileUploader id="fileUploader" name="myFileUpload" fileType="csv" uploadComplete="handleUploadComplete" typeMissmatch="checkTypeMissmatch" fileAllowed="fileTypeAllowed" />




      Controller:



      handleUploadComplete() =>
      var loFileUploader = sap.ui.getCore().byId("fileUploader");
      loFileUploader.setValueState(sap.ui.core.ValueState.None);
      var Title = sap.ui.getCore().byId("importCollectionTitle").getValue();

      var domRefFile = loFileUploader.getFocusDomRef(); //The Buggy boy

      var file = domRefFile.files[0];
      var reader = new FileReader();

      reader.onload = function(evt) {

      var postXMLUploadFile = evt.target.result.trim().replace(/r/g, "");
      var rows = postXMLUploadFile.split("n");

      //Import CSV file data

      };
      reader.readAsText(file);









      share|improve this question
















      This seems to be weird error. :)



      I am using the SAPIU5 fileuploder controller, it seems to be working fine. But sometimes the function getFocusDomRef is not able to fetch the parameters.



      One more strange behaviour is that, it is working in Mac (chrome) without any issues but with Windows (chrome) it fails sometimes.



      Using chrome Version 70.0.3538.102



      Below is the code snippet:



       <u:FileUploader id="fileUploader" name="myFileUpload" fileType="csv" uploadComplete="handleUploadComplete" typeMissmatch="checkTypeMissmatch" fileAllowed="fileTypeAllowed" />




      Controller:



      handleUploadComplete() =>
      var loFileUploader = sap.ui.getCore().byId("fileUploader");
      loFileUploader.setValueState(sap.ui.core.ValueState.None);
      var Title = sap.ui.getCore().byId("importCollectionTitle").getValue();

      var domRefFile = loFileUploader.getFocusDomRef(); //The Buggy boy

      var file = domRefFile.files[0];
      var reader = new FileReader();

      reader.onload = function(evt) {

      var postXMLUploadFile = evt.target.result.trim().replace(/r/g, "");
      var rows = postXMLUploadFile.split("n");

      //Import CSV file data

      };
      reader.readAsText(file);






      javascript file-upload sapui5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 11:53







      abhi5800

















      asked Nov 19 '18 at 6:17









      abhi5800abhi5800

      86111




      86111
























          1 Answer
          1






          active

          oldest

          votes


















          0














          For this functionality I've always used a button to get the files and using getFocusDomRef() never had a problem. You should also use FileReader() to read the content of the files asynchronously with FileReader.readAsText()
          after the download is actually finished.



          Use the FileReader.onload property that contains an event handler executed when the load event is fired.



          Using a button in your XML view:



          <u:FileUploader id="idfileUploader" sameFilenameAllowed="false" buttonText="" fileType="CSV" placeholder="Choose a CSV file"/>
          <Button text="Upload" press="onUpload" id="__uploadButton" tooltip="Upload CSV File"/>


          In the controller:



              onUpload: function() {
          //get file from uploader
          var domRef = this.getView().byId("idfileUploader").getFocusDomRef();
          var oFile = domRef.files[0];
          if (oFile && window.FileReader) {
          var reader = new FileReader();
          //onload function
          reader.onload = function(evt) {
          //file string
          var strCSV = evt.target.result;
          };
          reader.readAsText(oFile);
          } else {
          //File Reader not supported
          alert("Please Upload a CSV File!");
          }
          },


          Hope that helps!






          share|improve this answer


























          • Thank you for the input. I am using a button for upload also. ( May be that was 'also' the error ) and as you pointed out i have removed the "uploadComplete" from the fileuploader. Also i am using the fileupload.upload() ( editing my question ). As of now i did not face the issue again. :)

            – abhi5800
            Nov 19 '18 at 11:47











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369252%2fsapui-5-fileuploder-controller-function-getfocusdomref-not-working-sometime%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          For this functionality I've always used a button to get the files and using getFocusDomRef() never had a problem. You should also use FileReader() to read the content of the files asynchronously with FileReader.readAsText()
          after the download is actually finished.



          Use the FileReader.onload property that contains an event handler executed when the load event is fired.



          Using a button in your XML view:



          <u:FileUploader id="idfileUploader" sameFilenameAllowed="false" buttonText="" fileType="CSV" placeholder="Choose a CSV file"/>
          <Button text="Upload" press="onUpload" id="__uploadButton" tooltip="Upload CSV File"/>


          In the controller:



              onUpload: function() {
          //get file from uploader
          var domRef = this.getView().byId("idfileUploader").getFocusDomRef();
          var oFile = domRef.files[0];
          if (oFile && window.FileReader) {
          var reader = new FileReader();
          //onload function
          reader.onload = function(evt) {
          //file string
          var strCSV = evt.target.result;
          };
          reader.readAsText(oFile);
          } else {
          //File Reader not supported
          alert("Please Upload a CSV File!");
          }
          },


          Hope that helps!






          share|improve this answer


























          • Thank you for the input. I am using a button for upload also. ( May be that was 'also' the error ) and as you pointed out i have removed the "uploadComplete" from the fileuploader. Also i am using the fileupload.upload() ( editing my question ). As of now i did not face the issue again. :)

            – abhi5800
            Nov 19 '18 at 11:47
















          0














          For this functionality I've always used a button to get the files and using getFocusDomRef() never had a problem. You should also use FileReader() to read the content of the files asynchronously with FileReader.readAsText()
          after the download is actually finished.



          Use the FileReader.onload property that contains an event handler executed when the load event is fired.



          Using a button in your XML view:



          <u:FileUploader id="idfileUploader" sameFilenameAllowed="false" buttonText="" fileType="CSV" placeholder="Choose a CSV file"/>
          <Button text="Upload" press="onUpload" id="__uploadButton" tooltip="Upload CSV File"/>


          In the controller:



              onUpload: function() {
          //get file from uploader
          var domRef = this.getView().byId("idfileUploader").getFocusDomRef();
          var oFile = domRef.files[0];
          if (oFile && window.FileReader) {
          var reader = new FileReader();
          //onload function
          reader.onload = function(evt) {
          //file string
          var strCSV = evt.target.result;
          };
          reader.readAsText(oFile);
          } else {
          //File Reader not supported
          alert("Please Upload a CSV File!");
          }
          },


          Hope that helps!






          share|improve this answer


























          • Thank you for the input. I am using a button for upload also. ( May be that was 'also' the error ) and as you pointed out i have removed the "uploadComplete" from the fileuploader. Also i am using the fileupload.upload() ( editing my question ). As of now i did not face the issue again. :)

            – abhi5800
            Nov 19 '18 at 11:47














          0












          0








          0







          For this functionality I've always used a button to get the files and using getFocusDomRef() never had a problem. You should also use FileReader() to read the content of the files asynchronously with FileReader.readAsText()
          after the download is actually finished.



          Use the FileReader.onload property that contains an event handler executed when the load event is fired.



          Using a button in your XML view:



          <u:FileUploader id="idfileUploader" sameFilenameAllowed="false" buttonText="" fileType="CSV" placeholder="Choose a CSV file"/>
          <Button text="Upload" press="onUpload" id="__uploadButton" tooltip="Upload CSV File"/>


          In the controller:



              onUpload: function() {
          //get file from uploader
          var domRef = this.getView().byId("idfileUploader").getFocusDomRef();
          var oFile = domRef.files[0];
          if (oFile && window.FileReader) {
          var reader = new FileReader();
          //onload function
          reader.onload = function(evt) {
          //file string
          var strCSV = evt.target.result;
          };
          reader.readAsText(oFile);
          } else {
          //File Reader not supported
          alert("Please Upload a CSV File!");
          }
          },


          Hope that helps!






          share|improve this answer















          For this functionality I've always used a button to get the files and using getFocusDomRef() never had a problem. You should also use FileReader() to read the content of the files asynchronously with FileReader.readAsText()
          after the download is actually finished.



          Use the FileReader.onload property that contains an event handler executed when the load event is fired.



          Using a button in your XML view:



          <u:FileUploader id="idfileUploader" sameFilenameAllowed="false" buttonText="" fileType="CSV" placeholder="Choose a CSV file"/>
          <Button text="Upload" press="onUpload" id="__uploadButton" tooltip="Upload CSV File"/>


          In the controller:



              onUpload: function() {
          //get file from uploader
          var domRef = this.getView().byId("idfileUploader").getFocusDomRef();
          var oFile = domRef.files[0];
          if (oFile && window.FileReader) {
          var reader = new FileReader();
          //onload function
          reader.onload = function(evt) {
          //file string
          var strCSV = evt.target.result;
          };
          reader.readAsText(oFile);
          } else {
          //File Reader not supported
          alert("Please Upload a CSV File!");
          }
          },


          Hope that helps!







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '18 at 10:31

























          answered Nov 19 '18 at 10:40









          Andre FAndre F

          296213




          296213













          • Thank you for the input. I am using a button for upload also. ( May be that was 'also' the error ) and as you pointed out i have removed the "uploadComplete" from the fileuploader. Also i am using the fileupload.upload() ( editing my question ). As of now i did not face the issue again. :)

            – abhi5800
            Nov 19 '18 at 11:47



















          • Thank you for the input. I am using a button for upload also. ( May be that was 'also' the error ) and as you pointed out i have removed the "uploadComplete" from the fileuploader. Also i am using the fileupload.upload() ( editing my question ). As of now i did not face the issue again. :)

            – abhi5800
            Nov 19 '18 at 11:47

















          Thank you for the input. I am using a button for upload also. ( May be that was 'also' the error ) and as you pointed out i have removed the "uploadComplete" from the fileuploader. Also i am using the fileupload.upload() ( editing my question ). As of now i did not face the issue again. :)

          – abhi5800
          Nov 19 '18 at 11:47





          Thank you for the input. I am using a button for upload also. ( May be that was 'also' the error ) and as you pointed out i have removed the "uploadComplete" from the fileuploader. Also i am using the fileupload.upload() ( editing my question ). As of now i did not face the issue again. :)

          – abhi5800
          Nov 19 '18 at 11:47




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369252%2fsapui-5-fileuploder-controller-function-getfocusdomref-not-working-sometime%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown