diff --git a/docs/src/assets/images/reference/models/file/file.png b/docs/src/assets/images/reference/models/file/file.png new file mode 100644 index 0000000..d8e9d1c Binary files /dev/null and b/docs/src/assets/images/reference/models/file/file.png differ diff --git a/docs/src/assets/images/reference/models/file/table_file.png b/docs/src/assets/images/reference/models/file/table_file.png new file mode 100644 index 0000000..5ec48b2 Binary files /dev/null and b/docs/src/assets/images/reference/models/file/table_file.png differ diff --git a/docs/src/content/docs/reference/views/models/file.md b/docs/src/content/docs/reference/views/models/file.md new file mode 100644 index 0000000..722e9b6 --- /dev/null +++ b/docs/src/content/docs/reference/views/models/file.md @@ -0,0 +1,84 @@ +--- +title: File field +sidebar: + order: 1008 +description: Adomin file field reference +--- + +In the table page, a file field (with `isImage: true`) will look like this + +![field image](~/assets/images/reference/models/file/table_file.png) + +In the create / edit page + +![edit field image](~/assets/images/reference/models/file/file.png) + +## Config + +### isImage + +Optionnal, use this to enable things like preview/resizing + +### extnames + +Optionnal, array of extnames to check in backend validation, e.g. `['png', 'jpg']` + +### maxFileSize + +Optionnal, max file size to check in backend validation, e.g. `'1mb'` + +### noResize + +Optionnal, prevent resizing + +### maxWidth + +Optionnal, used during resizing + +### maxHeight + +Optionnal, used during resizing + +### quality + +Optionnal, used during resizing, must be between 0 and 1 (1 being the best quality / biggest file), default to 0.5 + +### subType + +Depending on how you store the file in your database, you will need a specific subType (with different options to configure), existing subTypes are: + +- `url` Use this when your file is represented as a string in your DB +- `custom` Use this when your file is stored in a custom way in your DB (e.g. a json format) + +### createFile (url subType) + +When using `url` subType the `createFile` function takes a file, persists it and returns the file URL + +:::note +💡 If there is an old file, it will be deleted using the `deleteFile` function you provided, so you don't have to worry about it +::: + +```ts +type CreateFunction = (file: MultipartFile) => Promise +``` + +### deleteFile (url subType) + +When using `url` subType the `deleteFile` function takes a file URL and should destroy the file +```ts +type DeleteFunction = (fileUrl: string) => Promise +``` + +### createFile (custom subType) + +When using `custom` subType the `createFile` function takes a `LucidRow` and a file, it must persist the file *and* update the model file column +```ts +type CreateFunction = (model: LucidRow, file: MultipartFile) => Promise +``` + +### deleteFile (custom subType) + +When using `custom` subType the `deleteFile` function takes a `LucidRow`, delete the *file* and update the file column +```ts +type DeleteFunction = (model: LucidRow) => Promise +``` diff --git a/docs/src/content/docs/reference/views/models/index.mdx b/docs/src/content/docs/reference/views/models/index.mdx index 967c6eb..7b60593 100644 --- a/docs/src/content/docs/reference/views/models/index.mdx +++ b/docs/src/content/docs/reference/views/models/index.mdx @@ -245,7 +245,7 @@ virtualColumns: [ ### [Enum field](/adomin/reference/views/models/enum/) -### File field +### [File field](/adomin/reference/views/models/file/) ### Array field