Skip to main content

createFileInputNode

workflow.createFileInputNode() is used to process the executor param of type: "file". It takes a file reference, JSON string, array, or path string and parses it to WorkflowResolvedFile[] via context.files.

Signature

workflow.createFileInputNode(
options?: FileInputNodeOptions,
): BaseNode<unknown, WorkflowResolvedFile[]>

Parameter

ParameterTypeDescription
optionsFileInputNodeOptionsControls the number of files, file types, node names, and meta information.

FileInputNodeOptions

FieldTypeDescription
namestringThe node name. The default value is "file-input".
acceptstring[]Allowed MIME or extensions, such as image/*, image/png, .pdf; an empty array means unlimited.
multiplebooleanWhether to allow multiple files, default true.
historyLimitnumberThe number of nodes retained in the execution history. The default value is 50.
metadataWorkflowNodeMetadataInputThe node displays meta information.

Input Format

InputExampleAnalysis results
Null valueundefined, null, ""[]
Path String"./input.png"A storage: "path" of WorkflowFileReference
JSON String"{\"id\":\"file1\",...}"JSON parse before normalizing references
Object{ id, name, storage, ... }a file reference
Array[{ id, ... }, { id, ... }]Multiple file references

WorkflowFileReference

FieldDescription
idThe file ID or path. Required.
nameFile name, use id when not passing.
mimeTypeThe MIME type, which defaults to application/octet-stream when not passed.
sizeThe size of the file. If the file is not passed, it is 0 or filled by the local stat.
kindFile type:image or file; inferred from MIME when not passing.
storageStorage Source:local, server, path, or url; default path.
workflowIdAssociation workflow.
conversationIdThe associated session.
createdAtThe creation time. The current time is not uploaded.
urlURL file source.
pathThe local path.

Output Object

Methods/FieldsTypeDescription
Referenced fieldWorkflowFileReference FieldThe output object retains the normalized reference fields.
readBuffer()Promise<Buffer>Read the contents of the file.
readBase64()Promise<string>Read base64 content.
readDataUrl()Promise<string>Read the data URL.
toLLMImagePart()Promise<LLMImagePart>Convert to LLM image input fragment. Non-pictures will be thrown wrong.
toJSON()WorkflowFileReferenceReturns a reference to a file that can be saved, without the contents of the file.

Dependent context

FieldDescription
context.filesWorkflowFileStore must be provided. input_validation is thrown when there is no file store.
context.abortSignalOptional. Node execution is checked by runNode.

Example

const imagesNode = workflow.createFileInputNode({
name: "images",
accept: ["image/png", "image/jpeg", "image/webp"],
multiple: true,
});

const files = await workflow.runNode(imagesNode, input.images, context);
const imageParts = await Promise.all(files.map((file) => file.toLLMImagePart()));