Skip to content

Commit 7561b73

Browse files
fix(ui): uppercase file extensions blocked for image upload
Closes #8284
1 parent caa9760 commit 7561b73

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

invokeai/frontend/web/src/common/hooks/useImageUploadButton.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { selectAutoAddBoardId } from 'features/gallery/store/gallerySelectors';
66
import { selectIsClientSideUploadEnabled } from 'features/system/store/configSlice';
77
import { toast } from 'features/toast/toast';
88
import { memo, useCallback } from 'react';
9-
import type { FileRejection } from 'react-dropzone';
9+
import type { Accept, FileRejection } from 'react-dropzone';
1010
import { useDropzone } from 'react-dropzone';
1111
import { useTranslation } from 'react-i18next';
1212
import { PiUploadBold } from 'react-icons/pi';
@@ -15,6 +15,18 @@ import type { ImageDTO } from 'services/api/types';
1515
import { assert } from 'tsafe';
1616
import type { SetOptional } from 'type-fest';
1717

18+
const addUpperCaseReducer = (acc: string[], ext: string) => {
19+
acc.push(ext);
20+
acc.push(ext.toUpperCase());
21+
return acc;
22+
};
23+
24+
export const dropzoneAccept: Accept = {
25+
'image/png': ['.png'].reduce(addUpperCaseReducer, [] as string[]),
26+
'image/jpeg': ['.jpg', '.jpeg', '.png'].reduce(addUpperCaseReducer, [] as string[]),
27+
'image/webp': ['.webp'].reduce(addUpperCaseReducer, [] as string[]),
28+
};
29+
1830
import { useClientSideUpload } from './useClientSideUpload';
1931
type UseImageUploadButtonArgs =
2032
| {
@@ -164,11 +176,7 @@ export const useImageUploadButton = ({
164176
getInputProps: getUploadInputProps,
165177
open: openUploader,
166178
} = useDropzone({
167-
accept: {
168-
'image/png': ['.png'],
169-
'image/jpeg': ['.jpg', '.jpeg', '.png'],
170-
'image/webp': ['.webp'],
171-
},
179+
accept: dropzoneAccept,
172180
onDropAccepted,
173181
onDropRejected,
174182
disabled: isDisabled,

invokeai/frontend/web/src/features/dnd/FullscreenDropzone.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ const zUploadFile = z
4141
// )
4242
.refine(
4343
(file) => {
44-
return ACCEPTED_IMAGE_TYPES.includes(file.type);
44+
return ACCEPTED_IMAGE_TYPES.includes(file.type.toLowerCase());
4545
},
4646
{ message: `File type is not supported` }
4747
)
4848
.refine(
4949
(file) => {
50-
return ACCEPTED_FILE_EXTENSIONS.some((ext) => file.name.endsWith(ext));
50+
return ACCEPTED_FILE_EXTENSIONS.some((ext) => file.name.toLowerCase().endsWith(ext));
5151
},
5252
{ message: `File extension is not supported` }
5353
);

invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelPanel/Fields/ModelImageUpload.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Box, IconButton, Image } from '@invoke-ai/ui-library';
2+
import { dropzoneAccept } from 'common/hooks/useImageUploadButton';
23
import { typedMemo } from 'common/util/typedMemo';
34
import { toast } from 'features/toast/toast';
45
import { useCallback, useState } from 'react';
@@ -72,11 +73,7 @@ const ModelImageUpload = ({ model_key, model_image }: Props) => {
7273
}, [model_key, t, deleteModelImage]);
7374

7475
const { getInputProps, getRootProps } = useDropzone({
75-
accept: {
76-
'image/png': ['.png'],
77-
'image/jpeg': ['.jpg', '.jpeg', '.png'],
78-
'image/webp': ['.webp'],
79-
},
76+
accept: dropzoneAccept,
8077
onDropAccepted,
8178
noDrag: true,
8279
multiple: false,

invokeai/frontend/web/src/features/nodes/components/sidePanel/workflow/WorkflowThumbnail/WorkflowThumbnailField.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Box, Button, Flex, Icon, IconButton, Image, Tooltip } from '@invoke-ai/ui-library';
2+
import { dropzoneAccept } from 'common/hooks/useImageUploadButton';
23
import { convertImageUrlToBlob } from 'common/util/convertImageUrlToBlob';
34
import { useCallback, useEffect, useState } from 'react';
45
import { useDropzone } from 'react-dropzone';
@@ -53,7 +54,7 @@ export const WorkflowThumbnailField = ({
5354
}, [onChange]);
5455

5556
const { getInputProps, getRootProps } = useDropzone({
56-
accept: { 'image/png': ['.png'], 'image/jpeg': ['.jpg', '.jpeg', '.png'] },
57+
accept: dropzoneAccept,
5758
onDropAccepted,
5859
noDrag: true,
5960
multiple: false,

invokeai/frontend/web/src/features/stylePresets/components/StylePresetForm/StylePresetImageField.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Box, Button, Flex, Icon, IconButton, Image, Tooltip } from '@invoke-ai/ui-library';
2+
import { dropzoneAccept } from 'common/hooks/useImageUploadButton';
23
import { useCallback } from 'react';
34
import { useDropzone } from 'react-dropzone';
45
import type { UseControllerProps } from 'react-hook-form';
@@ -26,7 +27,7 @@ export const StylePresetImageField = (props: UseControllerProps<StylePresetFormD
2627
}, [field]);
2728

2829
const { getInputProps, getRootProps } = useDropzone({
29-
accept: { 'image/png': ['.png'], 'image/jpeg': ['.jpg', '.jpeg', '.png'] },
30+
accept: dropzoneAccept,
3031
onDropAccepted,
3132
noDrag: true,
3233
multiple: false,

0 commit comments

Comments
 (0)