Class: S3Direct::UploadRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/s3direct/upload_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, sanitized_filename, options = {}) ⇒ UploadRequest

Returns a new instance of UploadRequest.



5
6
7
8
9
# File 'lib/s3direct/upload_request.rb', line 5

def initialize(path, sanitized_filename, options = {})
  @path = path
  @filename = sanitized_filename
  @options = options
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/s3direct/upload_request.rb', line 3

def filename
  @filename
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/s3direct/upload_request.rb', line 3

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/s3direct/upload_request.rb', line 3

def path
  @path
end

Instance Method Details

#attachment_filenameObject



34
35
36
# File 'lib/s3direct/upload_request.rb', line 34

def attachment_filename
  options[:attachment_filename].presence
end

#keyObject



11
12
13
# File 'lib/s3direct/upload_request.rb', line 11

def key
  ::File.join(@path, @filename)
end

#max_upload_sizeObject



42
43
44
# File 'lib/s3direct/upload_request.rb', line 42

def max_upload_size
  options.fetch(:max_upload_size, config.max_upload_size)
end

#s3_aclObject



38
39
40
# File 'lib/s3direct/upload_request.rb', line 38

def s3_acl
  options.fetch(:acl, config.default_acl)
end

#to_jsonObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/s3direct/upload_request.rb', line 15

def to_json
  data = {
    url: config.bucket_url,
    filename: @filename,
    key: key,
    policy: s3_upload_policy_document,
    signature: s3_upload_signature,
    acl: s3_acl,
    success_action_status: "200",
    'AWSAccessKeyId' => config.access_key
  }

  if attachment_filename
    data["Content-Disposition"] = %Q{attachment; filename="#{attachment_filename}"}
  end

  data.to_json
end