Class: Knjappserver::Httpsession::Post_multipart::File_upload
- Inherits:
-
Object
- Object
- Knjappserver::Httpsession::Post_multipart::File_upload
- Defined in:
- lib/include/class_httpsession_post_multipart.rb
Overview
This is the actual returned object for fileuploads. It is able to do various user-friendly things like save the content to a given path, return the filename, returns the content to a string and more.
Instance Method Summary collapse
-
#filename ⇒ Object
Returns the filename given for the fileupload.
-
#headers ⇒ Object
Returns the headers given for the fileupload.
-
#initialize(args) ⇒ File_upload
constructor
A new instance of File_upload.
-
#length ⇒ Object
Returns the size of the fileupload.
-
#save_to(filepath) ⇒ Object
Saves the content of the fileupload to a given path.
-
#size ⇒ Object
Returns the size of the upload.
-
#to_json(*args) ⇒ Object
This methods prevents the object from being converted to JSON.
-
#to_s ⇒ Object
Returns the content of the file-upload as a string.
Constructor Details
#initialize(args) ⇒ File_upload
Returns a new instance of File_upload.
95 96 97 |
# File 'lib/include/class_httpsession_post_multipart.rb', line 95 def initialize(args) @args = args end |
Instance Method Details
#filename ⇒ Object
Returns the filename given for the fileupload.
110 111 112 |
# File 'lib/include/class_httpsession_post_multipart.rb', line 110 def filename return @args["fname"] end |
#headers ⇒ Object
Returns the headers given for the fileupload. Type and more should be here.
115 116 117 |
# File 'lib/include/class_httpsession_post_multipart.rb', line 115 def headers return @args["headers"] end |
#length ⇒ Object
Returns the size of the fileupload.
105 106 107 |
# File 'lib/include/class_httpsession_post_multipart.rb', line 105 def length return @args["data"].length end |
#save_to(filepath) ⇒ Object
Saves the content of the fileupload to a given path.
125 126 127 128 129 |
# File 'lib/include/class_httpsession_post_multipart.rb', line 125 def save_to(filepath) File.open(filepath, "w") do |fp| fp.write(self.to_s) end end |
#size ⇒ Object
Returns the size of the upload.
100 101 102 |
# File 'lib/include/class_httpsession_post_multipart.rb', line 100 def size return @args["data"].length end |
#to_json(*args) ⇒ Object
This methods prevents the object from being converted to JSON. This can make some serious bugs.
132 133 134 |
# File 'lib/include/class_httpsession_post_multipart.rb', line 132 def to_json(*args) raise "File_upload-objects should not be converted to json." end |
#to_s ⇒ Object
Returns the content of the file-upload as a string.
120 121 122 |
# File 'lib/include/class_httpsession_post_multipart.rb', line 120 def to_s return @args["data"] end |