class Marten::DB::Field::File::File

Included Modules

Defined in:

marten/db/field/file/file.cr
marten/template/ext/db/field/file/file.cr

Constructors

Instance Method Summary

Macros inherited from module Marten::Template::Object

template_attributes(*names) template_attributes

Constructor Detail

def self.new(field : Field::File, name : ::String | Nil = nil) #

[View source]

Instance Method Detail

def attached? #

Returns true if a file is attached to the field and record.


[View source]
def committed? : Bool #

Returns true if the file is committed to the underlying storage.


[View source]
def delete(save = false) : Nil #

Deletes the associated filfe from the storage.

A Marten::DB::Errors::UnexpectedFieldValue error is raised if no file is associated with this object. Optionally, a #save boolean can be set to force the associated record to be saved along the way.


[View source]
def file=(file : ::File | Marten::HTTP::UploadedFile | Nil) #

Allows to associate a new file to the field.


[View source]
def name : String? #

Returns the name of the file or nil if no file is set.


[View source]
def open : IO #

Returns a IO object allowing to interact with the file's content.

A Marten::DB::Errors::UnexpectedFieldValue error is raised if no file is associated with this object.


[View source]
def save(filepath : ::String, content : IO, save = false) : Nil #

Allows to save a new file to the underlying storage.

A filepath string and a content IO must be specified. Optionally, a #save boolean can be set to force the associated record to be saved along the way.


[View source]
def size : Int64 #

Returns the #size of the file.

A Marten::DB::Errors::UnexpectedFieldValue error is raised if no file is associated with this object.


[View source]
def url : ::String #

Returns the URL of the file.

A Marten::DB::Errors::UnexpectedFieldValue error is raised if no file is associated with this object.


[View source]