Skip to content

Commit 8e2d7ca

Browse files
Fix bug: drag-and-drop, copy-paste, and upload don't work in nodes that specify upload folder that isn't 'input' (#4186)
1 parent e8dd26f commit 8e2d7ca

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/composables/node/useNodeImageUpload.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,29 @@ import type { LGraphNode } from '@comfyorg/litegraph'
33
import { useNodeDragAndDrop } from '@/composables/node/useNodeDragAndDrop'
44
import { useNodeFileInput } from '@/composables/node/useNodeFileInput'
55
import { useNodePaste } from '@/composables/node/useNodePaste'
6+
import type { ResultItemType } from '@/schemas/apiSchema'
67
import { api } from '@/scripts/api'
78
import { useToastStore } from '@/stores/toastStore'
89

910
const PASTED_IMAGE_EXPIRY_MS = 2000
1011

11-
const uploadFile = async (file: File, isPasted: boolean) => {
12+
interface ImageUploadFormFields {
13+
/**
14+
* The folder to upload the file to.
15+
* @example 'input', 'output', 'temp'
16+
*/
17+
type: ResultItemType
18+
}
19+
20+
const uploadFile = async (
21+
file: File,
22+
isPasted: boolean,
23+
formFields: Partial<ImageUploadFormFields> = {}
24+
) => {
1225
const body = new FormData()
1326
body.append('image', file)
1427
if (isPasted) body.append('subfolder', 'pasted')
28+
if (formFields.type) body.append('type', formFields.type)
1529

1630
const resp = await api.fetchApi('/upload/image', {
1731
method: 'POST',
@@ -36,6 +50,11 @@ interface ImageUploadOptions {
3650
* @example 'image/png,image/jpeg,image/webp,video/webm,video/mp4'
3751
*/
3852
accept?: string
53+
/**
54+
* The folder to upload the file to.
55+
* @example 'input', 'output', 'temp'
56+
*/
57+
folder?: ResultItemType
3958
}
4059

4160
/**
@@ -53,7 +72,9 @@ export const useNodeImageUpload = (
5372

5473
const handleUpload = async (file: File) => {
5574
try {
56-
const path = await uploadFile(file, isPastedFile(file))
75+
const path = await uploadFile(file, isPastedFile(file), {
76+
type: options.folder
77+
})
5778
if (!path) return
5879
return path
5980
} catch (error) {

src/composables/widgets/useImageUploadWidget.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useNodeImage, useNodeVideo } from '@/composables/node/useNodeImage'
55
import { useNodeImageUpload } from '@/composables/node/useNodeImageUpload'
66
import { useValueTransform } from '@/composables/useValueTransform'
77
import { t } from '@/i18n'
8-
import type { ResultItem } from '@/schemas/apiSchema'
8+
import type { ResultItem, ResultItemType } from '@/schemas/apiSchema'
99
import type { InputSpec } from '@/schemas/nodeDefSchema'
1010
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
1111
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
@@ -42,6 +42,7 @@ export const useImageUploadWidget = () => {
4242

4343
const inputOptions = inputData[1]
4444
const { imageInputName, allow_batch, image_folder = 'input' } = inputOptions
45+
const folder: ResultItemType | undefined = image_folder
4546
const nodeOutputStore = useNodeOutputStore()
4647

4748
const isAnimated = !!inputOptions.animated_image_upload
@@ -75,6 +76,7 @@ export const useImageUploadWidget = () => {
7576
allow_batch,
7677
fileFilter,
7778
accept,
79+
folder,
7880
onUploadComplete: (output) => {
7981
output.forEach((path) => addToComboValues(fileComboWidget, path))
8082
// @ts-expect-error litegraph combo value type does not support arrays yet

0 commit comments

Comments
 (0)