Skip to content

Function: FileUpload()

ts
function FileUpload(props: FileUploadProps): Block;

Defined in: src/renderer/blocks/index.ts:1251

File upload component.

If a validate function is provided, the block wraps it so the function runs in Node.js with the file's arrayBuffer populated via fetchFileChunks. The wrapper reads ctx lazily from a slot filled by render() — so the block must be created within the same call stack that hands it to render(ctx, ...).

The user's validator may return undefined (valid), a string (the error message), or the explicit {isValid, message, processedFile?} shape. All three are normalized to the explicit shape before reaching the underlying UI component.

Parameters

ParameterType
propsFileUploadProps

Returns

Block

Examples

ts
FileUpload({name: 'upload-file', fileUploadTitle: 'Upload files'});
ts
FileUpload({
  name: 'invoice',
  fileUploadTitle: 'Upload invoice',
  allowedTypes: {
    types: ['application/pdf', '.xlsx'],
    message: 'Only PDF or Excel files are allowed',
  },
  maxFileSize: {size: 5 * 1024 * 1024, message: 'File must be under 5MB'},
  validate: async (file) => {
    if (file.name.includes('draft')) return 'Draft files are not allowed';
    return undefined;
  },
});

Matterway Assistant SDK Documentation