class
Latch::Storage::FileSystem
- Latch::Storage::FileSystem
- Latch::Storage
- Reference
- Object
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.crConstant Summary
-
DEFAULT_DIRECTORY_PERMISSIONS =
File::Permissions.new(493) -
DEFAULT_PERMISSIONS =
File::Permissions.new(420)
Constructors
Instance Method Summary
- #clean? : Bool
-
#delete(id : String) : Nil
Deletes the file at the given location.
- #directory : String
- #directory_permissions : File::Permissions
-
#exists?(id : String) : Bool
Returns whether a file exists at the given location.
-
#expanded_directory : String
Returns the full expanded path including prefix.
-
#move(io : IO, id : String, **options) : Nil
Override move for efficient file system rename
-
#open(id : String, **options) : IO
Opens the file at the given location and returns an IO for reading.
-
#path_for(id : String) : String
Returns the full filesystem path for the given id.
- #permissions : File::Permissions
- #prefix : String | Nil
-
#upload(io : IO, id : String, move : Bool = false, **options) : Nil
Uploads an IO to the given location (id) in the storage.
-
#url(id : String, host : String | Nil = nil, **options) : String
Returns the URL for accessing the file at the given location.
Instance methods inherited from class Latch::Storage
delete(id : String) : Nil
delete,
exists?(id : String) : Bool
exists?,
move(io : IO, id : String, **options) : Nilmove(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
Instance Method Detail
Returns the full expanded path including prefix.
storage.expanded_directory
# => "/app/uploads/cache"
Opens the file at the given location and returns an IO for reading.
Returns the full filesystem path for the given id.
storage.path_for("abc123.jpg")
# => "/app/uploads/abc123.jpg"
Uploads an IO to the given location (id) in the 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"