class Kemal::FileUpload

Overview

A file part of a multipart/form-data request, spooled to a temporary file that is removed when the request is over.

Read it with #open, or hand #path to whatever stores it:

upload = env.params.files["image"]
upload.open { |file| IO.copy(file, destination) }
File.copy(upload.path, "public/uploads/#{upload.filename}")

Defined in:

kemal/file_upload.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(upload) #

[View source]

Instance Method Detail

def cleanup #

[View source]
def creation_time : Time | Nil #

[View source]
def filename : String | Nil #

[View source]
def headers : HTTP::Headers #

[View source]
def modification_time : Time | Nil #

[View source]
def open(& : File -> T) : T forall T #

Opens the upload for reading, yields the file and closes it.


[View source]
def path : String #

Path of the temporary file holding the upload.


[View source]
def read_time : Time | Nil #

[View source]
def size : UInt64 | Nil #

Bytes written to disk - not what the part's Content-Disposition claimed.


[View source]
def tempfile : File #

The upload as an open File, positioned at its start, kept open until the request is over. A handle per upload is what the default ulimit runs out of a few concurrent requests in; #open closes when it is done, and #path needs no handle at all.

DEPRECATED Use open(&) to read the upload or #path to move it


[View source]