From f7a89950ceb88d526d3da745cea0aa36b3c6b759 Mon Sep 17 00:00:00 2001 From: Suren Date: Thu, 24 Oct 2024 01:10:58 -0700 Subject: [PATCH] fixing .geojson file not supported with mac os (#10082) (#10625) * #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 * #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 (cherry picked from commit afafc5c7287bd3bb34a85f003360e04f018906dc) Co-authored-by: congchen1101 <161452326+congchen1101@users.noreply.github.com> --- .../dragZone/enhancers/__tests__/testData.js | 3 ++- .../import/dragZone/enhancers/processFiles.jsx | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 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 65a62202cf..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'; @@ -48,7 +49,8 @@ const checkFileType = (file) => { || 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) @@ -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}];