Skip to content

Commit

Permalink
fixing .geojson file not supported with mac os (geosolutions-it#10082)
Browse files Browse the repository at this point in the history
* geosolutions-it#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

* geosolutions-it#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
  • Loading branch information
congchen1101 authored and rmelarab-ngs committed Nov 5, 2024
1 parent 8953eb6 commit 553644c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
18 changes: 16 additions & 2 deletions web/client/components/import/dragZone/enhancers/processFiles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
readWMC,
readZip,
recognizeExt,
shpToGeoJSON
shpToGeoJSON,
readGeoJson
} from '../../../../utils/FileUtils';
import { geoJSONToLayer } from '../../../../utils/LayersUtils';

Expand All @@ -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)
Expand Down Expand Up @@ -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}];
Expand Down

0 comments on commit 553644c

Please sign in to comment.