From 254001e88048b534810073f8b56d64f0a8b542f5 Mon Sep 17 00:00:00 2001 From: stefano bovio Date: Thu, 15 Dec 2022 09:52:51 +0100 Subject: [PATCH] [Fixes #1305] Unable to upload GEOJSON files with .json extention (#1317) (#1366) Co-authored-by: David Quartey <42542676+DavidQuartz@users.noreply.github.com> --- .../client/js/routes/UploadDataset.jsx | 11 ++-------- .../client/js/utils/FileUtils.js | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/geonode_mapstore_client/client/js/routes/UploadDataset.jsx b/geonode_mapstore_client/client/js/routes/UploadDataset.jsx index d2e8ea6770..84bdffd94b 100644 --- a/geonode_mapstore_client/client/js/routes/UploadDataset.jsx +++ b/geonode_mapstore_client/client/js/routes/UploadDataset.jsx @@ -25,17 +25,10 @@ import UploadListContainer from '@js/routes/upload/UploadListContainer'; import UploadContainer from '@js/routes/upload/UploadContainer'; import { getConfigProp } from '@mapstore/framework/utils/ConfigUtils'; import { parseUploadResponse, processUploadResponse, parseUploadFiles } from '@js/utils/ResourceUtils'; - -function getFileNameParts(file) { - const { name } = file; - const nameParts = name.split('.'); - const ext = nameParts[nameParts.length - 1]; - const baseName = [...nameParts].splice(0, nameParts.length - 1).join('.'); - return { ext, baseName }; -} +import { getFileNameParts, getFileType } from '@js/utils/FileUtils'; function getDatasetFileType(file, supportedTypes) { - const { type } = file; + const type = getFileType(file); const { ext } = getFileNameParts(file); const datasetFileType = supportedTypes.find((fileType) => (fileType.ext || []).includes(ext) diff --git a/geonode_mapstore_client/client/js/utils/FileUtils.js b/geonode_mapstore_client/client/js/utils/FileUtils.js index dfc55d27fe..ac87d44699 100644 --- a/geonode_mapstore_client/client/js/utils/FileUtils.js +++ b/geonode_mapstore_client/client/js/utils/FileUtils.js @@ -40,3 +40,24 @@ export const determineResourceType = extension => { if (pcdExtensions.includes(extension)) return 'pcd'; return 'unsupported'; }; + +export const getFileNameParts = (file) => { + const { name } = file; + const nameParts = name.split('.'); + const ext = nameParts[nameParts.length - 1]; + const baseName = [...nameParts].splice(0, nameParts.length - 1).join('.'); + return { ext: ext.toLowerCase(), baseName }; +}; + +/** + * Get file type from file. + * In cases where the file type is application/json (which happens when file was originally .geojson converted to .json) + * We return json as file type + */ +export const getFileType = (file) => { + const { type } = file; + if (type === 'application/json') { + return 'json'; + } + return type; +};