Skip to content

Commit

Permalink
[Fixes #1305] Unable to upload GEOJSON files with .json extention (#1317
Browse files Browse the repository at this point in the history
) (#1366)

Co-authored-by: David Quartey <[email protected]>
  • Loading branch information
allyoucanmap and DavidQuartz authored Dec 15, 2022
1 parent 8a23bc7 commit 254001e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
11 changes: 2 additions & 9 deletions geonode_mapstore_client/client/js/routes/UploadDataset.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions geonode_mapstore_client/client/js/utils/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 254001e

Please sign in to comment.