Class: ServiceStack::UploadFile

Inherits:
Object
  • Object
show all
Defined in:
lib/servicestack/json_service_client.rb

Overview

A file uploaded in a multipart/form-data Request.

Its contents can be supplied as a String or any IO that responds to read, e.g. a File or StringIO.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_name: 'file', file_name: nil, content_type: nil, stream: nil) ⇒ UploadFile

Returns a new instance of UploadFile.



30
31
32
33
34
35
# File 'lib/servicestack/json_service_client.rb', line 30

def initialize(field_name: 'file', file_name: nil, content_type: nil, stream: nil)
  @field_name = field_name
  @file_name = file_name
  @content_type = content_type
  @stream = stream
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



28
29
30
# File 'lib/servicestack/json_service_client.rb', line 28

def content_type
  @content_type
end

#field_nameObject

Returns the value of attribute field_name.



28
29
30
# File 'lib/servicestack/json_service_client.rb', line 28

def field_name
  @field_name
end

#file_nameObject

Returns the value of attribute file_name.



28
29
30
# File 'lib/servicestack/json_service_client.rb', line 28

def file_name
  @file_name
end

#streamObject

Returns the value of attribute stream.



28
29
30
# File 'lib/servicestack/json_service_client.rb', line 28

def stream
  @stream
end

Instance Method Details

#contentsObject

The file contents to upload.



38
39
40
41
42
43
# File 'lib/servicestack/json_service_client.rb', line 38

def contents
  return @stream unless @stream.respond_to?(:read)

  @stream.binmode if @stream.respond_to?(:binmode)
  @stream.read
end