Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
p_zaccheddu
Contributor II
Contributor II

Extension can't upload file to content library only from Qlik Mobile.

Hello everyone.

We are using an extension to upload a file (a csv) to the content library. When an user fills a form and click "save", first the extension downloads the file, checks if the data is already present, then appends the data from the form to the csv and then uploads and overwrites the old version on the content library.
This is the snippet of the code used.

Download:

 

var url = window.location.origin+"/content/"+$scope.layout.props.library+"/"+$scope.layout.props.file;
$.get({
                url: url,
                success: function (data) {//check data
},
error: function(XMLHttpRequest, textStatus, errorThrown) { 
                  if (XMLHttpRequest.status == 0) {
                    $scope.msg = "Errore di rete!";
                  } else if (XMLHttpRequest.status == 404) {
                    $scope.msg = "URL non trovato!";
                  } else if (XMLHttpRequest.status == 500) {
                    $scope.msg = "Internal server error!";
                  }  else {
                    $scope.msg = "Errore sconosciuto: " + XMLHttpRequest.responseText;
                  }     
                  $scope.disabledSave = false;
                  $scope.$apply();
                },
                dataType: 'text'
              })

 

This bit of code works both on the browser and the mobile app. 

The code uses "window.location.origin" to get the server url. On a browser, it gets "https://[Server_name]", from the mobile app is "http://127.0.0.1:54187". I suppose the the mobile app works as a proxy, however the file is correctly downloaded. 

The problem is when we have to upload the file back to the repository. This is the code snippet:

 

  url = window.location.origin+"/qrs/contentlibrary/"+$scope.layout.props.library+"/uploadfile?externalpath="+$scope.layout.props.file+"&overwrite=true&Xrfkey=abcdefghijklmnop"
				 
				  alert(url);
                  $.post({
                    url: url,
                    headers:{
                      "x-Qlik-Xrfkey":"abcdefghijklmnop"
                    },
                    data: data,
                    success: function () {
                      console.log('file ok');
                      $scope.errorClass = "col-md-8 margintop10 inputOK";
                      $scope.msg = "Salvataggio completato con successo!";
                      $scope.disabledReload = false;
                      $scope.disabledSave = false;
                      $scope.$apply();
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) { 
                      if (XMLHttpRequest.status == 0) {
                        $scope.msg = "Errore di rete!";
                      } else if (XMLHttpRequest.status == 404) {
                        $scope.msg = "URL non trovato!";
                      } else if (XMLHttpRequest.status == 500) {
                        $scope.msg = "Internal server error!";
                      }  else {
                        $scope.msg = "Errore sconosciuto: " + XMLHttpRequest.responseText;
                      }     
                      $scope.disabledSave = false;
                      $scope.$apply();
                    },
                    dataType: 'text'
                  });

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) { 
                  if (XMLHttpRequest.status == 0) {
                    $scope.msg = "Errore di rete!";
                  } else if (XMLHttpRequest.status == 404) {
                    $scope.msg = "URL non trovato!";
                  } else if (XMLHttpRequest.status == 500) {
                    $scope.msg = "Internal server error!";
                  }  else {
                    $scope.msg = "Errore sconosciuto: " + XMLHttpRequest.responseText;
                  }     
                  $scope.disabledSave = false;
                  $scope.$apply();
                },
                dataType: 'text'
              });			

 

On a browser this code works perfectly, but on the mobile app returns "404" (it always uses "http://127.0.0.1:54187" as a server). I even tried to directly write in the code the server name "[Server_name]" as a const. It works on a browser, but on the mobile app the method XMLHttpRequest.status returns   "0". 

So how do I change the code so that it also works correctly on the mobile app?

Thank you!

Labels (3)
2 Replies
p_zaccheddu
Contributor II
Contributor II
Author

..Anyone..? 😢

p_zaccheddu
Contributor II
Contributor II
Author

Uh, perhaps my question wasn't clear enough? English isn't my first language...