Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(gallery): accept every media format the upload routes ingest

Lincoln Stein9c26b4e6177d
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index dac671563f..398b56b016 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -3606,7 +3606,7 @@
"downloadBoardWithOmission_other": "Download Board ({{count}} videos omitted)",
"downloadReady": "Download ready",
"downloadSelection": "Download selection",
- "dropMediaToUploadToBoard": "Drop images or videos to upload to {{name}}",
+ "dropMediaToUploadToBoard": "Drop images, videos, or audio to upload to {{name}}",
"emptyBoardUploadHint": "Drop media here or click to upload",
"exportProjectFromBoard": "Export project (.invk)",
"expandStarredItems": "Expand starred items",
diff --git a/invokeai/frontend/webv2/src/features/gallery/core/items.test.ts b/invokeai/frontend/webv2/src/features/gallery/core/items.test.ts
index 5eb461fe15..b23ee06588 100644
--- a/invokeai/frontend/webv2/src/features/gallery/core/items.test.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/core/items.test.ts
@@ -4,7 +4,9 @@ import type { GalleryImage, GeneratedImageContract } from './types';
import {
assertNeverGalleryItem,
+ classifyGalleryUpload,
compareGalleryItems,
+ getGalleryUploadAccept,
formatGalleryVideoDuration,
galleryImageItemToGalleryImage,
isGalleryImageItem,
@@ -242,3 +244,88 @@ describe('gallery item ordering', () => {
expect(sorted.map((item) => item.kind)).toEqual(['video', 'image']);
});
});
+
+describe('classifyGalleryUpload', () => {
+ it.each([
+ ['image/png', 'photo.bin', 'image'],
+ ['image/jpeg', 'photo.bin', 'image'],
+ ['image/jpg', 'photo.bin', 'image'],
+ ['image/webp', 'photo.bin', 'image'],
+ ['video/mp4', 'clip.bin', 'video'],
+ ['video/quicktime', 'clip.bin', 'video'],
+ ['video/webm', 'clip.webm', 'video'],
+ ['audio/mpeg', 'song.bin', 'video'],
+ ['audio/wav', 'memo.bin', 'video'],
+ ['', 'photo.PNG', 'image'],
+ ['', 'clip.MOV', 'video'],
+ ['', 'memo.m4a', 'video'],
+ ['application/octet-stream', 'photo.jpeg', 'image'],
+ ['application/octet-stream', 'song.mp3', 'video'],
+ ['binary/octet-stream', 'clip.MP4', 'video'],
+ ['application/octet-stream', 'clip.wmv', 'video'],
+ ['application/octet-stream', 'song.WMA', 'video'],
+ ['application/pdf', 'photo.png', 'image'],
+ ] as const)('classifies MIME %s and name %s as %s', (type, name, kind) => {
+ expect(classifyGalleryUpload(new File(['media'], name, { type }))).toEqual({ kind });
+ });
+
+ it.each([
+ ['application/pdf', 'document.pdf'],
+ ['', 'archive.zip'],
+ ['image/gif', 'animation.gif'],
+ ] as const)('rejects unsupported MIME %s and name %s', (type, name) => {
+ expect(classifyGalleryUpload(new File(['media'], name, { type }))).toBeNull();
+ });
+
+ it('uses a supported MIME before a conflicting extension', () => {
+ expect(classifyGalleryUpload(new File(['media'], 'looks-like-video.mp4', { type: 'image/png' }))).toEqual({
+ kind: 'image',
+ });
+ });
+});
+
+describe('getGalleryUploadAccept', () => {
+ // Spelled out rather than derived, and deliberately not sampled: this list is the
+ // frontend's copy of ACCEPTED_VIDEO_EXTENSIONS + ACCEPTED_AUDIO_EXTENSIONS in
+ // invokeai/app/api/routers/videos.py, and the picker greying out a file the route would
+ // have taken is the bug this exists to catch. A "trim to the common formats" edit must
+ // fail here, so an arrayContaining sample will not do.
+ it('offers every container and audio format the video upload route ingests', () => {
+ expect(getGalleryUploadAccept(['video']).split(',')).toEqual([
+ 'video/*',
+ 'audio/*',
+ '.mp4',
+ '.mov',
+ '.m4v',
+ '.webm',
+ '.mkv',
+ '.avi',
+ '.mpg',
+ '.mpeg',
+ '.3gp',
+ '.wmv',
+ '.asf',
+ '.mp3',
+ '.m4a',
+ '.aac',
+ '.wav',
+ '.flac',
+ '.ogg',
+ '.oga',
+ '.opus',
+ '.aiff',
+ '.aif',
+ '.wma',
+ ]);
+ });
+
+ it('keeps images to the three formats the app stores without re-encoding', () => {
+ expect(getGalleryUploadAccept(['image'])).toBe('image/png,image/jpeg,image/webp,.png,.jpg,.jpeg,.webp');
+ });
+
+ it('concatenates the kinds it is given, so a mixed picker offers both', () => {
+ expect(getGalleryUploadAccept(['image', 'video'])).toBe(
+ `${getGalleryUploadAccept(['image'])},${getGalleryUploadAccept(['video'])}`
+ );
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/gallery/core/items.ts b/invokeai/frontend/webv2/src/features/gallery/core/items.ts
index 2e33304f48..adb1750731 100644
--- a/invokeai/frontend/webv2/src/features/gallery/core/items.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/core/items.ts
@@ -171,3 +171,125 @@ export const formatGalleryVideoDuration = (durationSeconds: number): string => {
const hours = Math.floor(totalMinutes / 60);
return `${hours}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
};
+
+/**
+ * The media formats a gallery upload accepts, and the two things every upload surface needs
+ * from them: the file input's `accept` list and the kind a picked or dropped file uploads as.
+ *
+ * Both derive from one table so a picker cannot offer less than the upload route takes — the
+ * `accept` list and the classifier drifting apart is what left the gallery picker MP4-only
+ * while the video panel's reference picker took every format the server ingests.
+ *
+ * It lives here rather than in a module of its own on purpose: every upload surface is in the
+ * editor's initial graph, and a separate module is shared across enough chunk boundaries that
+ * Rolldown emits it standalone — an extra initial request, which the architecture budget pins
+ * exactly and refuses at any size. `items.ts` is already in that graph's `gallery-state` chunk.
+ */
+
+/**
+ * Accepted for each kind in the browser's own terms. The server normalizes every accepted
+ * upload to H.264 MP4 at ingest — foreign containers/codecs (.mov, HEVC, …) are remuxed or
+ * transcoded and audio files are wrapped into waveform videos — so audio uploads as 'video'.
+ *
+ * Video and audio use wildcards, which the server backs with its own prefix check. Images do
+ * not: the image route takes anything PIL can open and re-encodes it, but offering only the
+ * three formats the app round-trips losslessly is a deliberate (and unchanged) narrowing. The
+ * extension lists mirror the video upload route's and are the fallback for a file whose type
+ * the OS could not map, which the browser then offers as application/octet-stream.
+ */
+const GALLERY_UPLOAD_FORMATS: Record<GalleryItemKind, { extensions: readonly string[]; mimes: readonly string[] }> = {
+ image: {
+ extensions: ['.png', '.jpg', '.jpeg', '.webp'],
+ mimes: ['image/png', 'image/jpeg', 'image/webp'],
+ },
+ video: {
+ extensions: [
+ '.mp4',
+ '.mov',
+ '.m4v',
+ '.webm',
+ '.mkv',
+ '.avi',
+ '.mpg',
+ '.mpeg',
+ '.3gp',
+ '.wmv',
+ '.asf',
+ '.mp3',
+ '.m4a',
+ '.aac',
+ '.wav',
+ '.flac',
+ '.ogg',
+ '.oga',
+ '.opus',
+ '.aiff',
+ '.aif',
+ '.wma',
+ ],
+ mimes: ['video/*', 'audio/*'],
+ },
+};
+
+const GALLERY_UPLOAD_ENTRIES = (Object.keys(GALLERY_UPLOAD_FORMATS) as GalleryItemKind[]).flatMap((kind) =>
+ [...GALLERY_UPLOAD_FORMATS[kind].mimes, ...GALLERY_UPLOAD_FORMATS[kind].extensions].map(
+ (value) => [value, kind] as const
+ )
+);
+
+const isWildcard = (mime: string): boolean => mime.endsWith('/*');
+
+/** Exact MIME matches, for types no wildcard covers. */
+const GALLERY_UPLOAD_KIND_BY_MIME = new Map<string, GalleryItemKind>([
+ ...GALLERY_UPLOAD_ENTRIES.filter(([value]) => value.includes('/') && !isWildcard(value)),
+ // The legacy alias some Windows tools emit; the image route accepts it, but no picker
+ // needs to advertise it, so it is classified without being offered.
+ ['image/jpg', 'image'],
+]);
+
+/**
+ * Wildcard prefixes, derived from the table's own `*`-suffixed MIMEs rather than restated, so a
+ * kind that gains a wildcard cannot be offered in `accept` while the classifier still rejects
+ * it. These mirror `ACCEPTED_*_MIME_PREFIXES` on the upload routes.
+ */
+const GALLERY_UPLOAD_KIND_BY_MIME_PREFIX = GALLERY_UPLOAD_ENTRIES.filter(([value]) => isWildcard(value)).map(
+ ([mime, kind]) => [mime.slice(0, -1), kind] as const
+);
+
+// Matched with `endsWith`, never keyed, so a pair list rather than a Map.
+const GALLERY_UPLOAD_KIND_BY_EXTENSION = GALLERY_UPLOAD_ENTRIES.filter(([value]) => value.startsWith('.'));
+
+/**
+ * The file input `accept` list for the given kinds. Advisory only — every browser offers an
+ * "All files" escape hatch, so callers still classify what comes back.
+ */
+export const getGalleryUploadAccept = (kinds: readonly GalleryItemKind[]): string =>
+ kinds
+ .flatMap((kind) => [...GALLERY_UPLOAD_FORMATS[kind].mimes, ...GALLERY_UPLOAD_FORMATS[kind].extensions])
+ .join(',');
+
+/** Which upload route a picked file belongs to, or null when no route takes it. */
+export const classifyGalleryUpload = (file: Pick<File, 'name' | 'type'>): { kind: GalleryItemKind } | null => {
+ const mimeType = file.type.toLowerCase();
+ const mimeKind = GALLERY_UPLOAD_KIND_BY_MIME.get(mimeType);
+
+ if (mimeKind) {
+ return { kind: mimeKind };
+ }
+
+ for (const [prefix, kind] of GALLERY_UPLOAD_KIND_BY_MIME_PREFIX) {
+ if (mimeType.startsWith(prefix)) {
+ return { kind };
+ }
+ }
+
+ const lowerName = file.name.toLowerCase();
+
+ for (const [extension, kind] of GALLERY_UPLOAD_KIND_BY_EXTENSION) {
+ if (lowerName.endsWith(extension)) {
+ return { kind };
+ }
+ }
+
+ return null;
+};
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts
index f8f928366f..e7ded80991 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts
@@ -18,7 +18,6 @@ vi.mock('@platform/transport/http', () => ({
import {
addImagesToGalleryBoard,
- classifyGalleryUpload,
deleteGalleryBoard,
deleteGalleryImages,
downloadGalleryArchive,
@@ -811,45 +810,6 @@ describe('deleteGalleryImages partial failures', () => {
});
});
-describe('classifyGalleryUpload', () => {
- it.each([
- ['image/png', 'photo.bin', 'image'],
- ['image/jpeg', 'photo.bin', 'image'],
- ['image/jpg', 'photo.bin', 'image'],
- ['image/webp', 'photo.bin', 'image'],
- ['video/mp4', 'clip.bin', 'video'],
- ['video/quicktime', 'clip.bin', 'video'],
- ['video/webm', 'clip.webm', 'video'],
- ['audio/mpeg', 'song.bin', 'video'],
- ['audio/wav', 'memo.bin', 'video'],
- ['', 'photo.PNG', 'image'],
- ['', 'clip.MOV', 'video'],
- ['', 'memo.m4a', 'video'],
- ['application/octet-stream', 'photo.jpeg', 'image'],
- ['application/octet-stream', 'song.mp3', 'video'],
- ['binary/octet-stream', 'clip.MP4', 'video'],
- ['application/octet-stream', 'clip.wmv', 'video'],
- ['application/octet-stream', 'song.WMA', 'video'],
- ['application/pdf', 'photo.png', 'image'],
- ] as const)('classifies MIME %s and name %s as %s', (type, name, kind) => {
- expect(classifyGalleryUpload(new File(['media'], name, { type }))).toEqual({ kind });
- });
-
- it.each([
- ['application/pdf', 'document.pdf'],
- ['', 'archive.zip'],
- ['image/gif', 'animation.gif'],
- ] as const)('rejects unsupported MIME %s and name %s', (type, name) => {
- expect(classifyGalleryUpload(new File(['media'], name, { type }))).toBeNull();
- });
-
- it('uses a supported MIME before a conflicting extension', () => {
- expect(classifyGalleryUpload(new File(['media'], 'looks-like-video.mp4', { type: 'image/png' }))).toEqual({
- kind: 'image',
- });
- });
-});
-
describe('gallery uploads', () => {
beforeEach(() => {
accountLifecycle.activate('user-a');
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.ts
index c5da073446..f250b022bd 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.ts
@@ -77,70 +77,6 @@ const getDateFromBoardId = (boardId: string): string => boardId.slice(DATE_BOARD
const getUploadBoardId = (boardId: string): string | undefined =>
boardId === 'none' || boardId === ALL_READABLE_BOARDS_ID || isDateBoardId(boardId) ? undefined : boardId;
-export type GalleryUploadKind = 'image' | 'video';
-
-const GALLERY_UPLOAD_KIND_BY_MIME = new Map<string, GalleryUploadKind>([
- ['image/jpeg', 'image'],
- ['image/jpg', 'image'],
- ['image/png', 'image'],
- ['image/webp', 'image'],
-]);
-
-// The server normalizes every accepted upload to H.264 MP4 at ingest — foreign
-// containers/codecs (.mov, HEVC, …) are remuxed or transcoded, and audio files are
-// wrapped into waveform videos — so both video/* and audio/* upload as 'video'.
-const GALLERY_UPLOAD_KIND_BY_EXTENSION = new Map<string, GalleryUploadKind>([
- ['.jpeg', 'image'],
- ['.jpg', 'image'],
- ['.png', 'image'],
- ['.webp', 'image'],
- ['.mp4', 'video'],
- ['.mov', 'video'],
- ['.m4v', 'video'],
- ['.webm', 'video'],
- ['.mkv', 'video'],
- ['.avi', 'video'],
- ['.mpg', 'video'],
- ['.mpeg', 'video'],
- ['.3gp', 'video'],
- ['.wmv', 'video'],
- ['.asf', 'video'],
- ['.mp3', 'video'],
- ['.m4a', 'video'],
- ['.aac', 'video'],
- ['.wav', 'video'],
- ['.flac', 'video'],
- ['.ogg', 'video'],
- ['.oga', 'video'],
- ['.opus', 'video'],
- ['.aiff', 'video'],
- ['.aif', 'video'],
- ['.wma', 'video'],
-]);
-
-export const classifyGalleryUpload = (file: Pick<File, 'name' | 'type'>): { kind: GalleryUploadKind } | null => {
- const mimeType = file.type.toLowerCase();
- const mimeKind = GALLERY_UPLOAD_KIND_BY_MIME.get(mimeType);
-
- if (mimeKind) {
- return { kind: mimeKind };
- }
-
- if (mimeType.startsWith('video/') || mimeType.startsWith('audio/')) {
- return { kind: 'video' };
- }
-
- const lowerName = file.name.toLowerCase();
-
- for (const [extension, kind] of GALLERY_UPLOAD_KIND_BY_EXTENSION) {
- if (lowerName.endsWith(extension)) {
- return { kind };
- }
- }
-
- return null;
-};
-
interface BackendImageDTO {
image_name: string;
image_url: string;
diff --git a/invokeai/frontend/webv2/src/features/gallery/index.ts b/invokeai/frontend/webv2/src/features/gallery/index.ts
index 1958787cb4..ca7738c36f 100644
--- a/invokeai/frontend/webv2/src/features/gallery/index.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/index.ts
@@ -15,6 +15,7 @@ export {
compareGalleryItems,
formatGalleryVideoDuration,
galleryImageItemToGalleryImage,
+ getGalleryUploadAccept,
isGalleryImageItem,
legacyGeneratedImageToGalleryItem,
parseGalleryItemKey,
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
index 75a7c60b13..625282f41b 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
@@ -250,6 +250,7 @@ const actionMocks = {
setStarredOnly: vi.fn(),
toggleItemInSelection: vi.fn(),
updateSettings: vi.fn(),
+ uploadFiles: vi.fn(),
};
const imageActionMocks = {
deleteItems: vi.fn(),
@@ -297,7 +298,7 @@ const createActions = (): GalleryActions =>
toggleImageInSelection: actionMocks.toggleItemInSelection,
toggleItemInSelection: actionMocks.toggleItemInSelection,
updateSettings: actionMocks.updateSettings,
- uploadFiles: vi.fn(),
+ uploadFiles: actionMocks.uploadFiles,
}) as unknown as GalleryActions;
type CanonicalContextTarget = {
@@ -1079,6 +1080,33 @@ describe('GalleryImageGrid upload drop zone', () => {
expect(clickSpy).toHaveBeenCalledOnce();
});
+ it('offers every container and audio format the upload route ingests', async () => {
+ await renderGallery(createGallery({ items: [], pendingPlaceholders: [] }));
+
+ const accept = host?.querySelector<HTMLInputElement>('input[type="file"]')?.accept.split(',');
+
+ // The gallery once offered video/mp4 alone, so the OS picker greyed out every clip
+ // and audio file the server ingests. Parity with the video panel's reference upload.
+ expect(accept).toEqual(expect.arrayContaining(['image/png', 'video/*', 'audio/*', '.mov', '.mkv', '.mp3', '.wav']));
+ });
+
+ // Not a fix for the accept-list bug -- the drop path never consulted `accept` and already
+ // forwarded every format. This pins that: the handler must stay a pass-through, because
+ // filtering here by the picker's list would re-hide exactly what the picker just stopped
+ // hiding, and the classifier downstream is the single place that decides.
+ it('hands a dropped audio file to the upload action', async () => {
+ await renderGallery(createGallery({ items: [], pendingPlaceholders: [] }));
+
+ const dropTarget = host?.querySelector('[role="button"]');
+ const dataTransfer = new DataTransfer();
+ const song = new File(['audio'], 'song.mp3', { type: 'audio/mpeg' });
+
+ dataTransfer.items.add(song);
+ await interact(() => dropTarget?.dispatchEvent(new DragEvent('drop', { bubbles: true, dataTransfer })));
+
+ expect(actionMocks.uploadFiles).toHaveBeenCalledWith([song]);
+ });
+
it('keeps the no-match message for a search with no results instead of the upload target', async () => {
await renderGallery(createGallery({ items: [], pendingPlaceholders: [], searchTerm: 'nope' }));
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryMediaSlot.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryMediaSlot.tsx
index ebccb44c7a..138be49b07 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryMediaSlot.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryMediaSlot.tsx
@@ -3,14 +3,15 @@ import type { GalleryItem, GalleryItemKind, GalleryItemRef } from '@features/gal
import { Box, HStack, Icon, Image, Spinner, Stack, Text } from '@chakra-ui/react';
import { useDndMonitor } from '@dnd-kit/core';
-import { classifyGalleryUpload, getGalleryItemByRef } from '@features/gallery/data/backend';
+import { classifyGalleryUpload, getGalleryUploadAccept } from '@features/gallery/core/items';
+import { getGalleryItemByRef } from '@features/gallery/data/backend';
import { getGalleryImageThumbnailUrl } from '@features/gallery/data/imageUrls';
import { galleryBoardsOptions } from '@features/gallery/data/queries';
import { getGalleryVideoThumbnailUrl } from '@features/gallery/data/videoUrls';
import { isGalleryItemDragData, useGalleryItemDroppable } from '@features/gallery/ui/galleryDnd';
import { useGalleryUi } from '@features/gallery/ui/GalleryUiContext';
import { useGalleryUploadAction } from '@features/gallery/ui/useGalleryUploadAction';
-import { getGalleryUploadAccept, useGalleryUploadInput } from '@features/gallery/ui/useGalleryUploadInput';
+import { useGalleryUploadInput } from '@features/gallery/ui/useGalleryUploadInput';
import {
assertAccountScopeCurrent,
captureAccountScope,
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.browser.test.tsx
index 44ab6d585a..a116e05b26 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerPopover.browser.test.tsx
@@ -4,7 +4,7 @@ import type { GalleryBoard } from '@features/gallery/core/types';
import type { GalleryUiAdapter } from '@features/gallery/react';
import { ChakraProvider } from '@chakra-ui/react';
-import { legacyGeneratedImageToGalleryItem } from '@features/gallery/core/items';
+import { getGalleryUploadAccept, legacyGeneratedImageToGalleryItem } from '@features/gallery/core/items';
import { GalleryUiProvider } from '@features/gallery/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { system } from '@theme/system';
@@ -446,6 +446,23 @@ describe('GalleryPickerPopover', () => {
expect(galleryCommands.selectBoard).not.toHaveBeenCalled();
});
+ // The video-kind picker is the surface the widened accept list exists for: it is what the
+ // "Initial video" upload button opens. Asserted through a rendered picker because the
+ // narrowing that caused the bug lived in the view's `accept` wiring, not in the builder.
+ it('offers the full video and audio list on a video-kind picker', async () => {
+ const { dialog } = await openPicker(
+ <GalleryPickerPopover accept={['video']} label="Choose video" onPick={onPick}>
+ <button type="button">Choose video</button>
+ </GalleryPickerPopover>
+ );
+ const accept = dialog.querySelector<HTMLInputElement>('input[type="file"]')?.getAttribute('accept')?.split(',');
+
+ expect(accept).toContain('video/*');
+ expect(accept).toContain('audio/*');
+ expect(accept).toEqual(getGalleryUploadAccept(['video']).split(','));
+ expect(accept).not.toContain('image/png');
+ });
+
it('uploads into the current board and picks the result', async () => {
const uploaded = {
boardId: 'dogs',
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerView.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerView.tsx
index bab1a21233..a0df7ac740 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerView.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/picker/GalleryPickerView.tsx
@@ -3,7 +3,7 @@ import type { KeyboardEvent, RefObject } from 'react';
import { Box, HStack, Icon, Stack, Text } from '@chakra-ui/react';
import { getGalleryBoardLabel } from '@features/gallery/core/boardLabels';
-import { toGalleryItemKey } from '@features/gallery/core/items';
+import { getGalleryUploadAccept, toGalleryItemKey } from '@features/gallery/core/items';
import { BoardCover, BoardCoverIcon } from '@features/gallery/ui/GalleryBoardCover';
import { getGalleryBoardGroups } from '@features/gallery/ui/galleryBoardGroups';
import { GallerySearchHelp } from '@features/gallery/ui/GalleryItemSearch';
@@ -13,7 +13,7 @@ import { useGalleryUi } from '@features/gallery/ui/GalleryUiContext';
import { getGalleryUploadTargetLabel } from '@features/gallery/ui/GalleryUploadButton';
import { GalleryViewSegmentTabs } from '@features/gallery/ui/GalleryViewTabs';
import { useGalleryUploadAction } from '@features/gallery/ui/useGalleryUploadAction';
-import { getGalleryUploadAccept, useGalleryUploadInput } from '@features/gallery/ui/useGalleryUploadInput';
+import { useGalleryUploadInput } from '@features/gallery/ui/useGalleryUploadInput';
import { Button, CloseButton, IconButton } from '@platform/ui/Button';
import { MiddleTruncate } from '@platform/ui/MiddleTruncate';
import { segmentTabsPanelId, segmentTabsTabId } from '@platform/ui/SegmentTabs';
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx
index 124cfba4d7..a39f67bfcf 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx
@@ -25,18 +25,6 @@ const mocks = vi.hoisted(() => ({
}));
vi.mock('@features/gallery/data/backend', () => ({
- classifyGalleryUpload: (file: File) => {
- const type = file.type.toLowerCase();
- const name = file.name.toLowerCase();
-
- if (['image/jpeg', 'image/jpg', 'image/png', 'image/webp'].includes(type) || /\.(jpe?g|png|webp)$/.test(name)) {
- return { kind: 'image' as const };
- }
- if (type === 'video/mp4' || name.endsWith('.mp4')) {
- return { kind: 'video' as const };
- }
- return null;
- },
createGalleryBoard: vi.fn(),
deleteGalleryBoard: (...args: unknown[]) => mocks.deleteGalleryBoard(...args),
downloadGalleryArchive: (...args: unknown[]) => mocks.downloadGalleryArchive(...args),
@@ -72,7 +60,8 @@ vi.mock('react-i18next', () => ({
values?.board
)}. ${String(values?.failed)} failed.`,
'widgets.gallery.uploadSuccessTitle': `Uploaded ${String(values?.count)} files`,
- 'widgets.gallery.uploadUnsupported': 'No supported media files to upload (PNG, JPEG, WebP, or MP4).',
+ 'widgets.gallery.uploadUnsupported':
+ 'No supported media files to upload (PNG, JPEG, or WebP images; video files; or audio files).',
'widgets.gallery.uncategorized': 'Uncategorized',
'widgets.gallery.videoCount': `${String(values?.count)} videos`,
};
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.browser.test.tsx
index 485071ce0c..9fb85aede5 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.browser.test.tsx
@@ -21,18 +21,6 @@ const mocks = vi.hoisted(() => ({
}));
vi.mock('@features/gallery/data/backend', () => ({
- classifyGalleryUpload: (file: File) => {
- const type = file.type.toLowerCase();
- const name = file.name.toLowerCase();
-
- if (['image/jpeg', 'image/jpg', 'image/png', 'image/webp'].includes(type) || /\.(jpe?g|png|webp)$/.test(name)) {
- return { kind: 'image' as const };
- }
- if (type === 'video/mp4' || name.endsWith('.mp4')) {
- return { kind: 'video' as const };
- }
- return null;
- },
isDateBoardId: (boardId: string) => boardId.startsWith('by_date:'),
uploadGalleryImage: (...args: unknown[]) => mocks.uploadGalleryImage(...args),
uploadGalleryVideo: (...args: unknown[]) => mocks.uploadGalleryVideo(...args),
@@ -55,7 +43,8 @@ vi.mock('react-i18next', () => ({
values?.board
)}. ${String(values?.failed)} failed.`,
'widgets.gallery.uploadSuccessTitle': `Uploaded ${String(values?.count)} files`,
- 'widgets.gallery.uploadUnsupported': 'No supported media files to upload (PNG, JPEG, WebP, or MP4).',
+ 'widgets.gallery.uploadUnsupported':
+ 'No supported media files to upload (PNG, JPEG, or WebP images; video files; or audio files).',
'widgets.gallery.uncategorized': 'Uncategorized',
'widgets.gallery.videoCount': `${String(values?.count)} videos`,
};
@@ -410,7 +399,7 @@ describe('focused gallery upload action', () => {
expect(mocks.uploadGalleryVideo).not.toHaveBeenCalled();
expect(mocks.notificationsReportError).toHaveBeenCalledWith({
area: 'gallery-upload',
- message: 'No supported media files to upload (PNG, JPEG, WebP, or MP4).',
+ message: 'No supported media files to upload (PNG, JPEG, or WebP images; video files; or audio files).',
namespace: 'gallery',
});
});
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.ts
index 3110a62d3c..2449bb6bcb 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.ts
@@ -2,13 +2,12 @@ import type { GalleryItem } from '@features/gallery/core/items';
import type { GalleryBoard, GalleryView } from '@features/gallery/core/types';
import { getGalleryBoardLabel } from '@features/gallery/core/boardLabels';
-import { compareGalleryItems, legacyGeneratedImageToGalleryItem } from '@features/gallery/core/items';
import {
classifyGalleryUpload,
- isDateBoardId,
- uploadGalleryImage,
- uploadGalleryVideo,
-} from '@features/gallery/data/backend';
+ compareGalleryItems,
+ legacyGeneratedImageToGalleryItem,
+} from '@features/gallery/core/items';
+import { isDateBoardId, uploadGalleryImage, uploadGalleryVideo } from '@features/gallery/data/backend';
import { invalidateGallery } from '@features/gallery/data/queryCache';
import {
assertAccountScopeCurrent,
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadInput.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadInput.ts
index ee2a0e8004..11104a3163 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadInput.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadInput.ts
@@ -1,18 +1,8 @@
-import type { GalleryItemKind } from '@features/gallery/core/items';
-
+import { getGalleryUploadAccept } from '@features/gallery/core/items';
import { useCallback, useRef, type ChangeEvent } from 'react';
-const UPLOAD_ACCEPT_BY_KIND: Record<GalleryItemKind, string> = {
- image: 'image/png,image/jpeg,image/webp,.png,.jpg,.jpeg,.webp',
- video: 'video/mp4,.mp4',
-};
-
-/** The file input `accept` list for the given kinds. */
-export const getGalleryUploadAccept = (kinds: readonly GalleryItemKind[]): string =>
- kinds.map((kind) => UPLOAD_ACCEPT_BY_KIND[kind]).join(',');
-
-export const ACCEPTED_UPLOAD_EXTENSIONS = getGalleryUploadAccept(['image', 'video']);
-export const UPLOAD_INPUT_STYLE = { display: 'none' } as const;
+const ACCEPTED_UPLOAD_EXTENSIONS = getGalleryUploadAccept(['image', 'video']);
+const UPLOAD_INPUT_STYLE = { display: 'none' } as const;
/** The hidden-input picker every gallery upload trigger shares: change extracts files, resets the input (so re-picking the same file fires), and forwards. */
export const useGalleryUploadInput = (
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
index 4252b82d8d..e3d0f7ab8c 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
@@ -10,7 +10,7 @@ import type { ChangeEvent } from 'react';
import { Badge, Box, createListCollection, HStack, Icon, Image, Input, Spinner, Stack, Text } from '@chakra-ui/react';
import { useDndContext, useDndMonitor, useDroppable } from '@dnd-kit/core';
-import { galleryItems, galleryTransfers, toGalleryItemKey } from '@features/gallery';
+import { galleryItems, galleryTransfers, getGalleryUploadAccept, toGalleryItemKey } from '@features/gallery';
import { GalleryPickerPopover } from '@features/gallery/picker';
import { galleryImageUrls, galleryVideoUrls, isGalleryItemDragData } from '@features/gallery/utility';
import { resolveMiniMaxH3ReferenceImage } from '@features/video/core/dimensions';
@@ -55,38 +55,11 @@ import { useVideoUiActions } from './VideoUiContext';
*/
const DROP_ID = 'video-reference-list';
-const IMAGE_UPLOAD_ACCEPT = 'image/png,image/jpeg,image/webp,.png,.jpg,.jpeg,.webp';
+const IMAGE_UPLOAD_ACCEPT = getGalleryUploadAccept(['image']);
// One upload button for both media kinds: an uploaded audio file becomes a waveform video,
// so it occupies a VIDEO reference slot and shares that cap -- a separate audio button would
-// grey out with this one. The wildcards cover the ordinary case; the explicit extensions
-// (mirroring the upload route's accepted lists) are what match a file whose type the OS
-// could not map, which the browser then offers as octet-stream.
-const MEDIA_UPLOAD_ACCEPT = [
- 'video/*',
- 'audio/*',
- '.mp4',
- '.mov',
- '.m4v',
- '.webm',
- '.mkv',
- '.avi',
- '.mpg',
- '.mpeg',
- '.3gp',
- '.wmv',
- '.asf',
- '.mp3',
- '.m4a',
- '.aac',
- '.wav',
- '.flac',
- '.ogg',
- '.oga',
- '.opus',
- '.aiff',
- '.aif',
- '.wma',
-].join(',');
+// grey out with this one. The gallery's video accept list is exactly that set, audio included.
+const MEDIA_UPLOAD_ACCEPT = getGalleryUploadAccept(['video']);
const DROP_ZONE_FOCUS_PROPS = {
outlineColor: 'accent.focusRing',
outlineOffset: '2px',