class Shrine::UploadedFile
- Shrine::UploadedFile
- Reference
- Object
Included Modules
- JSON::Serializable
Defined in:
shrine/uploaded_file.crConstructors
- .new(id : String, storage_key : String, metadata : MetadataType = MetadataType.new)
- .new(pull : JSON::PullParser)
- .new(mapper : Mapper)
Class Method Summary
Instance Method Summary
-
#==(other : UploadedFile)
Returns true if the other UploadedFile is uploaded to the same storage and it has the same #id.
-
#[](key)
Shorthand for accessing metadata values.
-
#close
Part of complying to the IO interface.
- #content_type
-
#data : Hash(String, String | MetadataType)
Returns serializable hash representation of the uploaded file.
-
#delete
Calls
#delete
on the storage, which deletes the file from the storage. -
#download(**options)
Streams content into a newly created tempfile and returns it.
-
#download(**options, &)
Streams content into a newly created tempfile, yields it to the block, and at the end of the block automatically closes it.
-
#exists?
Calls
#exists?
on the storage, which checks whether the file exists on the storage. - #extension
- #gets_to_end(*args, **options)
- #gets_to_end(*args, **options, &)
- #id(*args, **options)
- #id(*args, **options, &)
- #io : IO
- #metadata(*args, **options)
- #metadata(*args, **options, &)
- #mime_type
-
#open(**options)
Calls
#open
on the storage to open the uploaded file for reading. - #open(**options, &)
-
#opened?
Returns whether the file has already been opened.
- #original_filename
- #pos(*args, **options)
- #pos(*args, **options, &)
-
#replace(io, **options)
Uploads a new file to this file's location and returns it.
- #size
-
#storage : Shrine::Storage::Base
Returns the storage that this file was uploaded to.
- #storage_key(*args, **options)
- #storage_key(*args, **options, &)
-
#stream(destination : IO, **options)
Streams uploaded file content into the specified destination.
- #to_json(*args, **options)
- #to_json(*args, **options, &)
-
#uploader
Returns an uploader object for the corresponding storage.
-
#url(**options) : String
Calls
#url
on the storage, forwarding any given URL options.
Constructor Detail
Class Method Detail
Instance Method Detail
Returns true if the other UploadedFile is uploaded to the same storage and it has the same #id.
Returns serializable hash representation of the uploaded file.
Streams content into a newly created tempfile and returns it.
uploaded_file.download
# => #<File:/var/folders/.../20180302-33119-1h1vjbq.jpg>
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
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
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)