class

Latch::Storage::FileSystem

Inherits Latch::Storage / Reference / Object

Local filesystem storage backend. Files are stored in a directory on the local filesystem. Supports an optional prefix for organizing files.

Latch.configure do |settings|
  settings.storages["cache"] = Latch::Storage::FileSystem.new(
    directory: "uploads",
    prefix: "cache"
  )
  settings.storages["store"] = Latch::Storage::FileSystem.new(
    directory: "uploads"
  )
end

Constants

DEFAULT_DIRECTORY_PERMISSIONS = File::Permissions.new(493)
DEFAULT_PERMISSIONS = File::Permissions.new(420)

Constructors

new(directory : String, prefix : String | Nil = nil, clean : Bool = true, permissions : File::Permissions = DEFAULT_PERMISSIONS, directory_permissions : File::Permissions = DEFAULT_DIRECTORY_PERMISSIONS)
Source

Instance methods

clean?
Source
delete(id : String) : Nil

Deletes the file at the given location.

Source
directory
Source
directory_permissions
Source
exists?(id : String) : Bool

Returns whether a file exists at the given location.

Source
expanded_directory

Returns the full expanded path including prefix.

storage.expanded_directory
# => "/app/uploads/cache"
Source
move(io : IO, id : String, **options) : Nil

Override move for efficient file system rename

Source
open(id : String, **options) : IO

Opens the file at the given location and returns an IO for reading.

Source
path_for(id : String) : String

Returns the full filesystem path for the given id.

storage.path_for("abc123.jpg")
# => "/app/uploads/abc123.jpg"
Source
permissions
Source
prefix
Source
upload(io : IO, id : String, move : Bool = false, **options) : Nil

Uploads an IO to the given location (id) in the storage.

Source
url(id : String, host : String | Nil = nil, **options) : String

Returns the URL for accessing the file at the given location.

storage.url("uploads/photo.jpg")
# => "/uploads/photo.jpg"
storage.url("uploads/photo.jpg", host: "https://example.com")
# => "https://example.com/uploads/photo.jpg"
Source