abstract class
Latch::Storage
- Latch::Storage
- Reference
- Object
Overview
Storage backends handle the actual persistence of uploaded files. Implementations must provide methods for uploading, retrieving, checking existence, and deleting files.
Direct Known Subclasses
Defined in:
latch/storage.crInstance Method Summary
-
#delete(id : String) : Nil
Deletes the file at the given location.
-
#exists?(id : String) : Bool
Returns whether a file exists at the given location.
-
#move(io : IO, id : String, **options) : Nil
Moves an IO from another location.
-
#move(file : Latch::StoredFile, id : String, **options) : Nil
Moves a file from another location.
-
#open(id : String, **options) : IO
Opens the file at the given location and returns an IO for reading.
-
#upload(io : IO, id : String, **options) : Nil
Uploads an IO to the given location (id) in the storage.
-
#url(id : String, **options) : String
Returns the URL for accessing the file at the given location.
Instance Method Detail
Deletes the file at the given location.
storage.delete("uploads/photo.jpg")
Does not raise if the file doesn't exist.
Returns whether a file exists at the given location.
storage.exists?("uploads/photo.jpg")
# => true
Moves a file from another location.
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.
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"})
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"