Module: Fog::Storage::AWS::PostObjectHiddenFields

Included in:
Mock, Real
Defined in:
lib/fog/aws/requests/storage/post_object_hidden_fields.rb

Instance Method Summary collapse

Instance Method Details

#post_object_hidden_fields(options = {}) ⇒ Object

Get a hash of hidden fields for form uploading to S3, in the form => :field_value Form should look like: <form action=“http://#bucket_name.s3.amazonaws.com/” method=“post” enctype=“multipart/form-data”> These hidden fields should then appear, followed by a field named ‘file’ which is either a textarea or file input.

Parameters:

  • options (defaults to: {})

    Hash:

Options Hash (options):

  • acl (String)

    access control list, in [‘private’, ‘public-read’, ‘public-read-write’, ‘authenticated-read’, ‘bucket-owner-read’, ‘bucket-owner-full-control’]

  • Cache-Control (String)

    same as REST header

  • Content-Type (String)

    same as REST header

  • Content-Disposition (String)

    same as REST header

  • Content-Encoding (String)

    same as REST header

  • Expires (Object)

    same as REST header

  • key (Object)

    key for object, set to ‘$filename’ to use filename provided by user

  • policy (Object)

    security policy for upload

  • success_action_redirect (Object)

    url to redirct to upon success

  • success_action_status (Object)

    status code to return on success, in [200, 201, 204]

  • x-amz-security (Object)

    token devpay security token

  • x-amz-meta... (Object)

    meta data tags

See Also:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/aws/requests/storage/post_object_hidden_fields.rb', line 25

def post_object_hidden_fields(options = {})
  options = options.dup
  if policy = options['policy']
    date = Fog::Time.now
    credential = "#{@aws_access_key_id}/#{@signer.credential_scope(date)}"
    extra_conditions = [
      {'x-amz-date' => date.to_iso8601_basic},
      {'x-amz-credential' => credential},
      {'x-amz-algorithm' => Fog::AWS::SignatureV4::ALGORITHM}
    ]

    extra_conditions << {'x-amz-security-token' => @aws_session_token } if @aws_session_token

    policy_with_auth_fields = policy.merge('conditions' => policy['conditions'] + extra_conditions)

    options['policy'] = Base64.encode64(Fog::JSON.encode(policy_with_auth_fields)).gsub("\n", "")
    options['X-Amz-Credential'] = credential
    options['X-Amz-Date'] = date.to_iso8601_basic
    options['X-Amz-Algorithm'] = Fog::AWS::SignatureV4::ALGORITHM
    if @aws_session_token
      options['X-Amz-Security-Token'] = @aws_session_token
    end
    options['X-Amz-Signature'] = @signer.derived_hmac(date).sign(options['policy']).unpack('H*').first
  end
  options
end