class VoiceBase::V2::Client::FileParam

Formats the contents of a file or string for inclusion with a multipart form post

Attributes

content[RW]
filename[RW]
k[RW]

Public Class Methods

new(k, filename, content) click to toggle source
# File lib/voicebase/v2/client.rb, line 219
def initialize(k, filename, content)
  @k, @filename, @content = k, filename, content
end

Public Instance Methods

to_multipart() click to toggle source
# File lib/voicebase/v2/client.rb, line 223
def to_multipart
  # If we can tell the possible mime-type from the filename, use the
  # first in the list; otherwise, use "application/octet-stream"
  mime_type = MIME::Types.type_for(filename)[0] || MIME::Types["application/octet-stream"][0]
  return "Content-Disposition: form-data; name=\"#{CGI::escape(k.to_s)}\"; filename=\"#{ filename }\"\r\n" +
    "Content-Type: #{ mime_type.simplified }\r\n\r\n#{ content }\r\n"
end