From d4defe3dba468ce1d0e1d999549f4609292a5012 Mon Sep 17 00:00:00 2001 From: congchen Date: Tue, 19 Mar 2024 09:47:57 +0100 Subject: [PATCH 1/2] #10081 FixBug .geojson file not supported in macos. - In macOS .geojson file will be identified as type of "application/geo+json". So in checkFileType and readFile functions, they will not go into MIME_LOOKUPS list to find the corresponding type. - Check first in MIME_LOOKUPS list and then the file.type will solve this problem. On behalf of DB Systel GmbH --- .../components/import/dragZone/enhancers/processFiles.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/client/components/import/dragZone/enhancers/processFiles.jsx b/web/client/components/import/dragZone/enhancers/processFiles.jsx index 65a62202cf..576827db43 100644 --- a/web/client/components/import/dragZone/enhancers/processFiles.jsx +++ b/web/client/components/import/dragZone/enhancers/processFiles.jsx @@ -41,7 +41,7 @@ const tryUnzip = (file) => { const checkFileType = (file) => { return new Promise((resolve, reject) => { const ext = recognizeExt(file.name); - const type = file.type || MIME_LOOKUPS[ext]; + const type = MIME_LOOKUPS[ext] || file.type; if (type === 'application/x-zip-compressed' || type === 'application/zip' || type === 'application/vnd.google-earth.kml+xml' @@ -63,7 +63,7 @@ const checkFileType = (file) => { */ const readFile = (onWarnings) => (file) => { const ext = recognizeExt(file.name); - const type = file.type || MIME_LOOKUPS[ext]; + const type = MIME_LOOKUPS[ext] || file.type; const projectionDefs = ConfigUtils.getConfigProp('projectionDefs') || []; const supportedProjections = (projectionDefs.length && projectionDefs.map(({code}) => code) || []).concat(["EPSG:4326", "EPSG:3857", "EPSG:900913"]); if (type === 'application/vnd.google-earth.kml+xml') { From ed5a57e1f2eb2481e80f47881dfdfcd28e10084a Mon Sep 17 00:00:00 2001 From: congchen Date: Mon, 8 Apr 2024 19:54:07 +0200 Subject: [PATCH 2/2] #10082 FixBug .geojson file not supported in macos. - added codes to support geojson in processFiles.jsx - fixed bug in testData.js in order to give a type by initialing a new File instance On behalf of DB Systel GmbH --- .../dragZone/enhancers/__tests__/testData.js | 3 ++- .../dragZone/enhancers/processFiles.jsx | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/web/client/components/import/dragZone/enhancers/__tests__/testData.js b/web/client/components/import/dragZone/enhancers/__tests__/testData.js index a88a370b7a..918b9090b3 100644 --- a/web/client/components/import/dragZone/enhancers/__tests__/testData.js +++ b/web/client/components/import/dragZone/enhancers/__tests__/testData.js @@ -16,7 +16,8 @@ export const getFile = (url, fileName = "file") => responseType: 'arraybuffer' })) .map( res => { - return new File([new Blob([res.data], {type: res.headers['response-type']})], fileName); + const contentType = res.headers['content-type'] === 'null' ? undefined : res.headers['content-type']; + return new File([res.data], fileName, {type: contentType}); }); // PDF_FILE: new File(b64toBlob('UEsDBAoAAAAAACGPaktDvrfoAQAAAAEAAAAKAAAAc2FtcGxlLnR4dGFQSwECPwAKAAAAAAAhj2pLQ7636AEAAAABAAAACgAkAAAAAAAAACAAAAAAAAAAc2FtcGxlLnR4dAoAIAAAAAAAAQAYAGILh+1EWtMBy3f86URa0wHLd/zpRFrTAVBLBQYAAAAAAQABAFwAAAApAAAAAAA=', 'application/pdf'), "file.pdf"), diff --git a/web/client/components/import/dragZone/enhancers/processFiles.jsx b/web/client/components/import/dragZone/enhancers/processFiles.jsx index 576827db43..9afc0b2fae 100644 --- a/web/client/components/import/dragZone/enhancers/processFiles.jsx +++ b/web/client/components/import/dragZone/enhancers/processFiles.jsx @@ -24,7 +24,8 @@ import { readWMC, readZip, recognizeExt, - shpToGeoJSON + shpToGeoJSON, + readGeoJson } from '../../../../utils/FileUtils'; import { geoJSONToLayer } from '../../../../utils/LayersUtils'; @@ -41,14 +42,15 @@ const tryUnzip = (file) => { const checkFileType = (file) => { return new Promise((resolve, reject) => { const ext = recognizeExt(file.name); - const type = MIME_LOOKUPS[ext] || file.type; + const type = file.type || MIME_LOOKUPS[ext]; if (type === 'application/x-zip-compressed' || type === 'application/zip' || type === 'application/vnd.google-earth.kml+xml' || type === 'application/vnd.google-earth.kmz' || type === 'application/gpx+xml' || type === 'application/json' - || type === 'application/vnd.wmc') { + || type === 'application/vnd.wmc' + || type === 'application/geo+json') { resolve(file); } else { // Drag and drop of compressed folders doesn't correctly send the zip mime type (windows, also conflicts with installations of WinRar) @@ -63,7 +65,7 @@ const checkFileType = (file) => { */ const readFile = (onWarnings) => (file) => { const ext = recognizeExt(file.name); - const type = MIME_LOOKUPS[ext] || file.type; + const type = file.type || MIME_LOOKUPS[ext]; const projectionDefs = ConfigUtils.getConfigProp('projectionDefs') || []; const supportedProjections = (projectionDefs.length && projectionDefs.map(({code}) => code) || []).concat(["EPSG:4326", "EPSG:3857", "EPSG:900913"]); if (type === 'application/vnd.google-earth.kml+xml') { @@ -114,6 +116,18 @@ const readFile = (onWarnings) => (file) => { return [{...f, "fileName": file.name}]; }); } + if (type === 'application/geo+json') { + return readGeoJson(file).then(f => { + const projection = get(f, 'geoJSON.map.projection'); + if (projection) { + if (supportedProjections.includes(projection)) { + return [{...f.geoJSON, "fileName": file.name}]; + } + throw new Error("PROJECTION_NOT_SUPPORTED"); + } + return [{...f.geoJSON, "fileName": file.name}]; + }); + } if (type === 'application/vnd.wmc') { return readWMC(file).then((config) => { return [{...config, "fileName": file.name}];