3liz / qgis-wfsOutputExtension

QGIS Server plugin to add Output Formats to WFS GetFeature request.
GNU General Public License v2.0
10 stars 6 forks source link

No the good name and extension in the end of the file #49

Closed JLHI closed 2 years ago

JLHI commented 2 years ago

Hello,

I've installed the plugin V1.7 on Lizmap 3.5.1 and Qgis-server 3.22.

The export work, but the name and the extension of the export are not good. exemple :

f2f487be-d23b-4b1e-a8c1-e422b8711a3d

But when a re-write manually the entire url : Server & query, it work well.

Have an idea?

Thanks.

JLHI commented 2 years ago

Issue came the version of map.js file. I copied a file to an older version and now it work's. Specificaly, the function "downloadFile( url, parameters, callback ) ", hope this help !

gioman commented 2 years ago

@JLHI Hi, I see the same on Chrome and Edge, but not Firefox (tested on Win 10).

Issue came the version of map.js file. I copied a file to an older version and now it work's. Specificaly, the function "downloadFile( url, parameters, callback ) ", hope this help !

Can you be more specific about how to fix this? Thanks.

JLHI commented 2 years ago

Ok, you have to search an older version ( like 4.9) and in the map.js, take the "downloadFile()" function and replace it in your map.js. The older work well bu not the new.

the function : function downloadFile( url, parameters, callback ) { var xhr = new XMLHttpRequest(); xhr.open('POST', url, true); xhr.responseType = 'arraybuffer'; xhr.onload = function () { if (this.status === 200) { var filename = ""; var disposition = xhr.getResponseHeader('Content-Disposition'); if (disposition && disposition.indexOf('attachment') !== -1) { var filenameRegex = /filename[^;=\n]=((['"]).?\2|[^;\n]*)/; var matches = filenameRegex.exec(disposition); if (matches != null && matches[1]) filename = matches[1].replace(/['"]/g, ''); } var type = xhr.getResponseHeader('Content-Type');

          var blob = typeof File === 'function'
              ? new File([this.response], filename, { type: type })
              : new Blob([this.response], { type: type });
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
              // IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
              window.navigator.msSaveBlob(blob, filename);
          } else {
              var URL = window.URL || window.webkitURL;
              var downloadUrl = URL.createObjectURL(blob);

              if (filename) {
                  // use HTML5 a[download] attribute to specify filename
                  var a = document.createElement("a");
                  // safari doesn't support this yet
                  if (typeof a.download === 'undefined') {
                      window.location = downloadUrl;
                  } else {
                      a.href = downloadUrl;
                      a.download = filename;
                      document.body.appendChild(a);
                      a.click();
                  }
              } else {
                  window.location = downloadUrl;
              }

              setTimeout(function () { URL.revokeObjectURL(downloadUrl); }, 100); // cleanup
          }
      }

      // Note 31/01/2022
      // REMOVE WHEN THE QGIS SERVER BUG HAS BEEN FIXED
      // Related PR for QGIS Master https://github.com/qgis/QGIS/pull/47051
      // It should be fixed for 3.24.1 and 3.22.5
      if (this.status == 400) {
        // Check for parenthesis inside the layer name
        // There is a bug to be fixed in QGIS Server WFS request for this context
        var typeName = parameters['TYPENAME'];
        const parenthesis_regex = /[\(\)]/g;
        const has_parenthesis = typeName.match(parenthesis_regex);
        if (has_parenthesis) {
          var error_message = 'The selected features cannot be exported due to a known bug in QGIS Server.';
          error_message += '<br/>Please ask the map editor to remove the parenthesis in the layer name.';
        } else {
          var error_message = lizDict['layer.export.unknown.export.error'];
        };

        mAddMessage(error_message, 'error', true);
        return false;
      }
      // Execute callback if any
      if (typeof callback === 'function'){
        callback();
      }
  };
  xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  xhr.send($.param(parameters, true));

}

gioman commented 2 years ago

Ok, you have to search an older version ( like 4.9) and in the map.js, take the "downloadFile()" function and replace it in your map.js. The older work well bu not the new.

@JLHI thanks for the reply, but sorry for the stupid question, version 4.9 of what? there is no 4.9 version of this extension or of the lizmap web client. Anyway I think that this should be considered a bug and so this ticket should be reopened.

JLHI commented 2 years ago

@gioman gioman

You said : there is no 4.9 version of this extension or of the lizmap web client There is ! If you got to the main lizmap web client Git hub page, you should find the release section, with all versions of the code, like the 4.9.

gioman commented 2 years ago

There is !

@JLHI https://github.com/3liz/lizmap-web-client/releases

3.5 is the latest

JLHI commented 2 years ago

My bad, it's 3.4.9 version 👍

gioman commented 2 years ago

My bad, it's 3.4.9 version 👍

@JLHI thanks, I'll give it a try. Can you please reopen this ticket? Or even better open a ticket in the Lizmap Web Client repo? This is a plain bug.

gioman commented 2 years ago

@JLHI did not worked for me. Did you had to do some additional step after patching the function? Can you confirm that the file you patched is

lizmap/www/assets/js/map.js

and not

lizmap/www/js/map.js

?

JLHI commented 2 years ago

You have to replace this file (map.js) ==> /[srv or var]/www/html/lizmap/www/js/map.js , because it's this file used by the server, as shown in console of a web-browser.

And i dont re-open because it's a qgis-server error, and not a lizmap error.

gioman commented 2 years ago

And i dont re-open because it's a qgis-server error, and not a lizmap error.

@JLHI if patching map.js in LMWC code fixes it then is a LMWC bug, not a qgis server one. Do you agree?

You have to replace this file (map.js) ==> /[srv or var]/www/html/lizmap/www/js/map.js , because it's this file used by the server, as shown in console of a web-browser.

will try.

JLHI commented 2 years ago

You're right, but it's write in the code, lizdev's are waiting for a fix, and the next code is here. We can use this plugin by a "hack". Also, the lizmap futur code is ready....not qgis server code, you see?

gioman commented 2 years ago

You have to replace this file (map.js) ==> /[srv or var]/www/html/lizmap/www/js/map.js , because it's this file used by the server, as shown in console of a web-browser.

@JLHI still does not work for me (did you replace just that function or the entire map.js?).

We can use this plugin by a "hack". Also, the lizmap futur code is ready....not qgis server code, you see?

no sorry, I can't understand you.

@rldhont @Gustry can you help understand here were the problem is, if there is something that can be patched (and where) and if this ticket should be reopened here, or elsewhere? thanks.

rldhont commented 2 years ago

First of all Update your lizmap web client to 3.5.4 or 3.5.5 the name of the downloaded file has been fixed

gioman commented 2 years ago

@rldhont thanks. I was looking to understand if there was a patch for the 3.4 series, but I'll upgrade to 3.5 instead then.

rldhont commented 2 years ago

@gioman version 3.4.12 has the bugfix https://github.com/3liz/lizmap-web-client/pull/2988

gioman commented 2 years ago

@gioman version 3.4.12 has the bugfix 3liz/lizmap-web-client#2988

Thanks, missed that commit.