From 408103263756d645e10bfb7a753a08b882351144 Mon Sep 17 00:00:00 2001 From: Maksim Kovalev Date: Mon, 14 Mar 2022 20:00:16 +0200 Subject: [PATCH] #93261 - Usage of maxFileSize in geo upload form is removed --- .../components/geo_upload_form/geo_file_picker.tsx | 14 +++++++++----- .../file_upload/public/importer/geo/index.ts | 4 ++-- .../file_upload/public/importer/validate_file.ts | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/file_upload/public/components/geo_upload_form/geo_file_picker.tsx b/x-pack/plugins/file_upload/public/components/geo_upload_form/geo_file_picker.tsx index a349a5b82d372..bf76184762b1e 100644 --- a/x-pack/plugins/file_upload/public/components/geo_upload_form/geo_file_picker.tsx +++ b/x-pack/plugins/file_upload/public/components/geo_upload_form/geo_file_picker.tsx @@ -29,6 +29,7 @@ interface State { isLoadingPreview: boolean; importer: GeoFileImporter | null; previewSummary: string | null; + isNoLimit: boolean; } export class GeoFilePicker extends Component { @@ -40,6 +41,7 @@ export class GeoFilePicker extends Component { isLoadingPreview: false, importer: null, previewSummary: null, + isNoLimit: true, }; async componentDidMount() { @@ -64,7 +66,7 @@ export class GeoFilePicker extends Component { if (files && files.length) { const file = files[0]; try { - const importer = geoImporterFactory(file); + const importer = geoImporterFactory(file, this.state.isNoLimit); this.setState( { defaultIndexName: file.name.split('.')[0].toLowerCase(), @@ -136,10 +138,12 @@ export class GeoFilePicker extends Component { values: { fileTypes: GEO_FILE_TYPES.join(', ') }, })}
- {i18n.translate('xpack.fileUpload.geoFilePicker.maxSize', { - defaultMessage: 'Max size: {maxFileSize}', - values: { maxFileSize: getMaxBytesFormatted() }, - })} + + {!this.state.isNoLimit && + i18n.translate('xpack.fileUpload.geoFilePicker.maxSize', { + defaultMessage: 'Max size: {maxFileSize}', + values: { maxFileSize: getMaxBytesFormatted() }, + })} ); } diff --git a/x-pack/plugins/file_upload/public/importer/geo/index.ts b/x-pack/plugins/file_upload/public/importer/geo/index.ts index fd75d17ec5e71..e8cdd26199e05 100644 --- a/x-pack/plugins/file_upload/public/importer/geo/index.ts +++ b/x-pack/plugins/file_upload/public/importer/geo/index.ts @@ -12,8 +12,8 @@ import { getFileExtension, validateFile } from '../validate_file'; export const GEO_FILE_TYPES = [...GEOJSON_FILE_TYPES, ...SHAPEFILE_TYPES]; -export function geoImporterFactory(file: File): GeoFileImporter { - validateFile(file, GEO_FILE_TYPES); +export function geoImporterFactory(file: File, isNoLimit?: boolean): GeoFileImporter { + validateFile(file, GEO_FILE_TYPES, isNoLimit); const extension = getFileExtension(file); return GEOJSON_FILE_TYPES.includes(extension) diff --git a/x-pack/plugins/file_upload/public/importer/validate_file.ts b/x-pack/plugins/file_upload/public/importer/validate_file.ts index 0a087e91a63f3..8d1baa5398c07 100644 --- a/x-pack/plugins/file_upload/public/importer/validate_file.ts +++ b/x-pack/plugins/file_upload/public/importer/validate_file.ts @@ -16,8 +16,8 @@ export function getFileExtension(file: File) { return '.' + extension; } -export function validateFile(file: File, types: string[]) { - if (file.size > getMaxBytes()) { +export function validateFile(file: File, types: string[], isNoLimit?: boolean) { + if (file.size > getMaxBytes() && !isNoLimit) { throw new Error( i18n.translate('xpack.fileUpload.fileSizeError', { defaultMessage: 'File size {fileSize} exceeds maximum file size of {maxFileSize}',