Class: Sdk4me::Multipart::FileParam
- Inherits:
-
Object
- Object
- Sdk4me::Multipart::FileParam
- Defined in:
- lib/sdk4me/client/multipart.rb
Overview
Formats the contents of a file or string for inclusion with a multipart form post
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#k ⇒ Object
Returns the value of attribute k.
Instance Method Summary collapse
-
#initialize(key, filename, content) ⇒ FileParam
constructor
A new instance of FileParam.
- #to_multipart ⇒ Object
Constructor Details
#initialize(key, filename, content) ⇒ FileParam
Returns a new instance of FileParam.
60 61 62 63 64 |
# File 'lib/sdk4me/client/multipart.rb', line 60 def initialize(key, filename, content) @k = key @filename = filename @content = content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
58 59 60 |
# File 'lib/sdk4me/client/multipart.rb', line 58 def content @content end |
#filename ⇒ Object
Returns the value of attribute filename.
58 59 60 |
# File 'lib/sdk4me/client/multipart.rb', line 58 def filename @filename end |
#k ⇒ Object
Returns the value of attribute k.
58 59 60 |
# File 'lib/sdk4me/client/multipart.rb', line 58 def k @k end |
Instance Method Details
#to_multipart ⇒ Object
66 67 68 69 70 71 |
# File 'lib/sdk4me/client/multipart.rb', line 66 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] %(Content-Disposition: form-data; name="#{CGI.escape(k.to_s)}"; filename="#{filename}"\r\n) + %(Content-Type: #{mime_type.simplified}\r\n\r\n#{content.force_encoding('UTF-8')}\r\n) end |