class Knjappserver::Httpsession::Post_multipart::File_upload

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.

Public Class Methods

new(args) click to toggle source
# File lib/include/class_httpsession_post_multipart.rb, line 95
def initialize(args)
  @args = args
end

Public Instance Methods

filename() click to toggle source

Returns the filename given for the fileupload.

# File lib/include/class_httpsession_post_multipart.rb, line 110
def filename
  return @args["fname"]
end
headers() click to toggle source

Returns the headers given for the fileupload. Type and more should be here.

# File lib/include/class_httpsession_post_multipart.rb, line 115
def headers
  return @args["headers"]
end
length() click to toggle source

Returns the size of the fileupload.

# File lib/include/class_httpsession_post_multipart.rb, line 105
def length
  return @args["data"].length
end
save_to(filepath) click to toggle source

Saves the content of the fileupload to a given path.

# 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() click to toggle source

Returns the size of the upload.

# File lib/include/class_httpsession_post_multipart.rb, line 100
def size
  return @args["data"].length
end
to_json(*args) click to toggle source

This methods prevents the object from being converted to JSON. This can make some serious bugs.

# 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() click to toggle source

Returns the content of the file-upload as a string.

# File lib/include/class_httpsession_post_multipart.rb, line 120
def to_s
  return @args["data"]
end