class

Latch::Storage

Inherits Reference / Object

Storage backends handle the actual persistence of uploaded files. Implementations must provide methods for uploading, retrieving, checking existence, and deleting files.

Instance methods

delete(id : String) : Nil

Deletes the file at the given location.

storage.delete("uploads/photo.jpg")

Does not raise if the file doesn't exist.

Source
exists?(id : String) : Bool

Returns whether a file exists at the given location.

storage.exists?("uploads/photo.jpg")
# => true
Source
move(io : IO, id : String, **options) : Nil

Moves an IO from another location.

Source
move(file : Latch::StoredFile, id : String, **options) : Nil

Moves a file from another location.

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

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

io = storage.open("uploads/photo.jpg")
content = io.gets_to_end
io.close

Raises Latch::FileNotFound if the file doesn't exist.

Source
upload(io : IO, id : String, **options) : Nil

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

storage.upload(io, "uploads/photo.jpg")
storage.upload(io, "uploads/photo.jpg", metadata: {"filename" => "original.jpg"})
Source
url(id : String, **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

Nested types