class Latch::Storage::FileSystem

Overview

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

Defined in:

latch/storage/file_system.cr

Constant Summary

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

Constructors

Instance Method Summary

Instance methods inherited from class Latch::Storage

delete(id : String) : Nil delete, exists?(id : String) : Bool exists?, move(io : IO, id : String, **options) : Nil
move(file : Latch::StoredFile, id : String, **options) : Nil
move
, open(id : String, **options) : IO open, upload(io : IO, id : String, **options) : Nil upload, url(id : String, **options) : String url

Constructor Detail

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

[View source]

Instance Method Detail

def clean? : Bool #

[View source]
def delete(id : String) : Nil #

Deletes the file at the given location.


[View source]
def directory : String #

[View source]
def directory_permissions : File::Permissions #

[View source]
def exists?(id : String) : Bool #

Returns whether a file exists at the given location.


[View source]
def expanded_directory : String #

Returns the full expanded path including prefix.

storage.expanded_directory
# => "/app/uploads/cache"

[View source]
def move(io : IO, id : String, **options) : Nil #

Override move for efficient file system rename


[View source]
def open(id : String, **options) : IO #

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


[View source]
def path_for(id : String) : String #

Returns the full filesystem path for the given id.

storage.path_for("abc123.jpg")
# => "/app/uploads/abc123.jpg"

[View source]
def permissions : File::Permissions #

[View source]
def prefix : String | Nil #

[View source]
def upload(io : IO, id : String, move : Bool = false, **options) : Nil #

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


[View source]
def url(id : String, host : String | Nil = nil, **options) : String #
Description copied from class Latch::Storage

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"

[View source]