Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new widget to store arbitrary files as base64 using a file input #3263

Open
leplatrem opened this issue Jun 5, 2024 · 1 comment
Open
Assignees

Comments

@leplatrem
Copy link
Contributor

This would allow users to store relatively small files as attributes on records instead of using attachments.

Typical use-case is to store the thumbnail of the file that is attached on the record.

In order to do this, we will need:

  • a new widget that turns the file picked in the <input type="file"> into base64
  • to leverage this widget in our Records form

The record schema would be:

properties:
  thumbnail:
    type: string

And the collection UI schema:

uiSchema:
  thumbnail:
    ui:widget: base64input

Then instead of contributing a new widget in the rjsf upstream project, we can follow the pattern that we currently have for our local JSON editor, and inject it ourselves during form instantiation:

export default function JSONEditor({
readonly,
disabled,
value,
onChange,
}: Props) {
const onCodeChange = (code: string, viewUpdate: ViewUpdate) => {
onChange(code);
};
return readonly || disabled ? (
<pre>{value}</pre>
) : (
<CodeMirror
value={value}
onChange={onCodeChange}
height="auto"
extensions={[langs.json()]}
indentWithTab={false}
/>
);
}

const uiSchema: UiSchema = {
data: {
"ui:widget": JSONEditor,
},
};

In this case we would replace occurrences of base64input by instances of our base64 widget.

See also:

@nathan-barrett
Copy link

Thanks @leplatrem - feel free to assign me and I'll take a stab at it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants