Class: Knjappserver::Httpsession::Post_multipart::File_upload

Inherits:
Object
  • Object
show all
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

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

#filenameObject

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

#headersObject

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

#lengthObject

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

#sizeObject

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_sObject

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