Skip to content

annotation Athena::Framework::Annotations::MapUploadedFile #

Enables the ATHR::RequestBody resolver for the parameter this annotation is applied to based on ATH::Request#files, if the related bundle configuration is enabled.

If the type of the parameter this annotation is applied to is ATH::UploadedFile, then it will attempt to resolve the first file based on the name of the parameter. This can be customized via the name field on the annotation. If the type is a Array(ATH::UploadedFile) then all files with that name will be resolved, not just the first.

When resolving a single file that is not found, and the parameter has a default value or is nilable, then that default value, or nil, will be used. If the parameter does not have a default and is not nilable, then an error response is returned. When resolving an array of files, then an empty array would be provided.

class UserController < ATH::Controller
  @[ARTA::Post("/avatar")]
  def avatar(
    @[ATHA::MapUploadedFile(constraints: AVD::Constraints::Image.new)]
    profile_picture : ATH::UploadedFile,
  ) : Nil
    # ...
  end
end

Configuration#

Optional Arguments#

name#

Type: String? Default: nil

Use this value to resole the files instead of the name of the parameter the annotation is applied to.

constraints#

Type: AVD::Constraint | Array(AVD::Constraint) | Nil Default: nil

Validate the uploaded file(s) against these constraint(s). Mostly commonly will be a single AVD::Constraints::File or AVD::Constraints::Image constraint.