class Shrine::UploadedFile

Included Modules

Defined in:

shrine/uploaded_file.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(id : String, storage_key : String, metadata : MetadataType = MetadataType.new) #

[View source]
def self.new(pull : JSON::PullParser) #

[View source]
def self.new(mapper : Mapper) #

[View source]

Class Method Detail

def self.from_json(json : String) #

[View source]

Instance Method Detail

def ==(other : UploadedFile) #

Returns true if the other UploadedFile is uploaded to the same storage and it has the same #id.


[View source]
def [](key) #

Shorthand for accessing metadata values.


[View source]
def close #

Part of complying to the IO interface. It delegates to the internally opened IO object.


[View source]
def content_type #

[View source]
def data : Hash(String, String | MetadataType) #

Returns serializable hash representation of the uploaded file.


[View source]
def delete #

Calls #delete on the storage, which deletes the file from the storage.


[View source]
def download(**options) #

Streams content into a newly created tempfile and returns it.

uploaded_file.download
# => #<File:/var/folders/.../20180302-33119-1h1vjbq.jpg>

[View source]
def download(**options, &) #

Streams content into a newly created tempfile, yields it to the block, and at the end of the block automatically closes it. In this case the return value of the method is the block return value.

uploaded_file.download { |tempfile| tempfile.gets_to_end } # tempfile is deleted

[View source]
def exists? #

Calls #exists? on the storage, which checks whether the file exists on the storage.


[View source]
def extension #

[View source]
def gets_to_end(*args, **options) #

[View source]
def gets_to_end(*args, **options, &) #

[View source]
def id(*args, **options) #

def id(*args, **options, &) #

def io : IO #

[View source]
def metadata(*args, **options) #

def metadata(*args, **options, &) #

def mime_type #

[View source]
def open(**options) #

Calls #open on the storage to open the uploaded file for reading. Most storages will return a lazy IO object which dynamically retrieves file content from the storage as the object is being read.

If a block is given, the opened IO object is yielded to the block, and at the end of the block it's automatically closed. In this case the return value of the method is the block return value.

If no block is given, the opened IO object is returned.

uploaded_file.open # => IO object returned by the storage
uploaded_file.read # => "..."
uploaded_file.close

# or

uploaded_file.open { |io| io.read } # the IO is automatically closed

[View source]
def open(**options, &) #

[View source]
def opened? #

Returns whether the file has already been opened.


[View source]
def original_filename #

[View source]
def pos(*args, **options) #

[View source]
def pos(*args, **options, &) #

[View source]
def replace(io, **options) #

Uploads a new file to this file's location and returns it.


[View source]
def size #

[View source]
def storage : Shrine::Storage::Base #

Returns the storage that this file was uploaded to.


[View source]
def storage_key(*args, **options) #

def storage_key(*args, **options, &) #

def stream(destination : IO, **options) #

Streams uploaded file content into the specified destination. The destination object is given directly to IO.copy.

If the uploaded file is already opened, it will be simply rewinded after streaming finishes. Otherwise the uploaded file is opened and then closed after streaming.

uploaded_file.stream(IO::Memory.new)

[View source]
def to_json(*args, **options) #

def to_json(*args, **options, &) #

def uploader #

Returns an uploader object for the corresponding storage.


[View source]
def url(**options) : String #

Calls #url on the storage, forwarding any given URL options.


[View source]