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 support for model and schema image fields #32

Open
ellmetha opened this issue Jun 4, 2022 · 0 comments
Open

Add support for model and schema image fields #32

ellmetha opened this issue Jun 4, 2022 · 0 comments

Comments

@ellmetha
Copy link
Member

ellmetha commented Jun 4, 2022

Description

Marten presently supports file model fields and schema fields, which respectively allow (i) to attach files to model records and (ii) to process / validate uploaded files as part of schemas. Another common need of web applications is to handle image uploading and validation. Ideally, it should be possible to attach images to models using an image model field:

class BlogPost < Marten::Model
  field :id, :big_int, primary_key: true, auto: true
  field :title, :string, max_size: 100
  field :header_image, :image # uses the default media file storage
  field :other_image, :image, storage: my_custome_storage
end

It should also be possible to define image fields as part of schemas:

class BlogPostSchema < Marten::Model
  field :title, :string, max_size: 100
  field :header_image, :image
end

This comes with an additional set of requirements: it becomes necessary to validate the type of files being attached to model records or processed by schemas in order to ensure that only image files are allowed. Non-image files should result in validation errors. Validating that a file is indeed an image could be achieved by leveraging some external image processing shards; and a few candidates could be considered:

Regardless of the chosen shard, this shouldn't become a "hard" dependency of Marten: Marten should work as expected even if the chosen shard is not installed, but using image model / schema fields wouldn't not be possible.

@ellmetha ellmetha changed the title Add support for image model / schema fields Add support for model and schema image fields Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant