Class: ActionDispatch::Http::UploadedFile

Inherits:
Object
  • Object
show all
Defined in:
runtime/action_dispatch/multipart.rb,
runtime/action_dispatch/multipart.rbs

Overview

A multipart part, and what fixture_file_upload hands a test: the name it was uploaded under, its declared type, and its bytes. Data-backed rather than file-backed so a part never touches the disk before the storage service decides where it lives.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, original_filename, content_type) ⇒ UploadedFile

Returns a new instance of UploadedFile.

Parameters:



9
# File 'runtime/action_dispatch/multipart.rbs', line 9

def initialize: (String data, String original_filename, String content_type) -> void

Instance Attribute Details

#content_type ⇒ String (readonly)

Returns the value of attribute content_type.

Returns:



8
9
10
# File 'runtime/action_dispatch/multipart.rbs', line 8

def content_type
  @content_type
end

#original_filename ⇒ String (readonly)

Returns the value of attribute original_filename.

Returns:



7
8
9
# File 'runtime/action_dispatch/multipart.rbs', line 7

def original_filename
  @original_filename
end

Class Method Details

.from_params(sub, key) ⇒ UploadedFile?

the file under key in a params sub-hash, or nil when the request carried no file there (absent, or a text field — the bare filename a urlencoded form posts for a file input is a String, not a file).

Parameters:

Returns:

  • (UploadedFile, nil) —

    the file, or nil when none was uploaded



58
# File 'runtime/action_dispatch/multipart.rb', line 58

def self.from_params: (Hash[String, untyped] sub, String key) -> ActionDispatch::Http::UploadedFile?

.name_of(file) ⇒ String

the uploaded name for a params record's to_h, or "" for none.

Parameters:

Returns:

  • (String) —

    the uploaded name, "" when there is no file



81
# File 'runtime/action_dispatch/multipart.rb', line 81

def self.name_of: (ActionDispatch::Http::UploadedFile? file) -> String

.provided(sub, key) ⇒ Boolean

did the request carry a file under key? The file counterpart of ActionController::Params.provided.

Parameters:

Returns:

  • (Boolean) —

    true when a file part was uploaded under key



73
# File 'runtime/action_dispatch/multipart.rb', line 73

def self.provided: (Hash[String, untyped] sub, String key) -> bool

Instance Method Details

#read ⇒ String

Returns:



10
# File 'runtime/action_dispatch/multipart.rbs', line 10

def read: () -> String

#size ⇒ Integer

Returns:



11
# File 'runtime/action_dispatch/multipart.rbs', line 11

def size: () -> Integer

#to_s ⇒ String

the uploaded name, which is what a params hash carrying this file stringifies to.

Returns:

  • (String) —

    the uploaded file name



47
# File 'runtime/action_dispatch/multipart.rb', line 47

def to_s: () -> String