Skip to content

Commit

Permalink
elastic#93261 - Usage of maxFileSize in geo upload form is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimkovalev committed Mar 14, 2022
1 parent 3853bf4 commit 4081032
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface State {
isLoadingPreview: boolean;
importer: GeoFileImporter | null;
previewSummary: string | null;
isNoLimit: boolean;
}

export class GeoFilePicker extends Component<Props, State> {
Expand All @@ -40,6 +41,7 @@ export class GeoFilePicker extends Component<Props, State> {
isLoadingPreview: false,
importer: null,
previewSummary: null,
isNoLimit: true,
};

async componentDidMount() {
Expand All @@ -64,7 +66,7 @@ export class GeoFilePicker extends Component<Props, State> {
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(),
Expand Down Expand Up @@ -136,10 +138,12 @@ export class GeoFilePicker extends Component<Props, State> {
values: { fileTypes: GEO_FILE_TYPES.join(', ') },
})}
<br />
{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() },
})}
</span>
);
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/file_upload/public/importer/geo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/file_upload/public/importer/validate_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand Down

0 comments on commit 4081032

Please sign in to comment.