athena-framework / athena

An ecosystem of reusable, independent components
https://athenaframework.org
MIT License
211 stars 17 forks source link

File Uploads #442

Open Blacksmoke16 opened 3 months ago

Blacksmoke16 commented 3 months ago

One of the next use cases I'd like to tackle is that of uploading files. Currently there isn't a great way to handle this because using HTTP::FormData.parse from the stdlib. I think it would be nice if a lot of this was abstracted away and were able to just work with already uploaded files. The current plan is like:

@[ARTA::Post("/upload")]
def upload_file(@[ATHA::MapUploadedFile] upload : ATH::UploadedFile) : Nil
  # ...
end

which would be a pretty nice API vs working with HTTP::FormData.parse directly.

The annotation would have the ability to define AVD::Constraint(s) on it, as well as set the name of the form data field, and what HTTP status code should be used if validation fails. This'll make things fairly easy to control the supported mime types, max size, etc.