class

Marten::DB::Field::File

Inherits Marten::DB::Field::Base / Reference / Object

Represents a file field.

Constructors

new(id : ::String, storage : Core::Storage::Base | Nil = nil, max_size : Int32 = 100, default : ::String | Nil = nil, upload_to : Proc(::String, ::String) | ::String = "", blank = false, null = false, unique = false, index = false, db_column = nil)
Source

Instance methods

default

Returns the default value of the field if any.

Source
empty_value?(value) : ::Bool

Returns true if the value is considered empty by the field.

Source
from_db(value) : Marten::DB::Field::File::File | Nil

Converts the raw DB value to the corresponding field value.

Source
from_db_result_set(result_set : ::DB::ResultSet) : Marten::DB::Field::File::File | Nil

Extracts the field value from a DB result set and returns the right object corresponding to this value.

Source
max_size

Returns the max size of the string corresponding to the file path to be stored in the database.

Source
prepare_save(record, new_record = false)

Runs pre-save logic for the specific field and record at hand.

This method does nothing by default but can be overridden for specific fields that need to set values on the model instance before save or perform any pre-save logic.

Source
sanitize_filename(filename : ::String) : ::String
Source
storage

Returns the storage object that should be used to store the file.

Source
to_column

Returns a migration column object corresponding to the field at hand.

Source
to_db(value) : ::DB::Any

Converts the field value to the corresponding DB value.

Source
upload_to

Returns the path where the file should be stored or a proc returning this path.

Source

Nested types