lib/services/s3.js
function createPresignedPost(params, callback) {
    if (typeof params === 'function' && callback === undefined) {
      callback = params;
      params = null;
    }

    params = AWS.util.copy(params || {});
    var boundParams = this.config.params || {};
    var bucket = params.Bucket || boundParams.Bucket,
      self = this,
      config = this.config,
      endpoint = AWS.util.copy(this.endpoint);
    if (!config.s3BucketEndpoint) {
      endpoint.pathname = '/' + bucket;
    }

    function finalizePost() {
      return {
        url: AWS.util.urlFormat(endpoint),
        fields: self.preparePostFields(
          config.credentials,
          config.region,
          bucket,
          params.Fields,
          params.Conditions,
          params.Expires
        )
      };
    }

    if (callback) {
      config.getCredentials(function (err) {
        if (err) {
          callback(err);
        }

        callback(null, finalizePost());
      });
    } else {
      return finalizePost();
    }
  }
function createPresignedPost(params, callback) {
    if (typeof params === 'function' && callback === undefined) {
      callback = params;
      params = null;
    }

    params = AWS.util.copy(params || {});
    var boundParams = this.config.params || {};
    var bucket = params.Bucket || boundParams.Bucket,
      self = this,
      config = this.config,
      endpoint = AWS.util.copy(this.endpoint);
    if (!config.s3BucketEndpoint) {
      endpoint.pathname = '/' + bucket;
    }

    function finalizePost() {
      return {
        url: AWS.util.urlFormat(endpoint),
        fields: self.preparePostFields(
          config.credentials,
          config.region,
          bucket,
          params.Fields,
          params.Conditions,
          params.Expires
        )
      };
    }

    if (callback) {
      config.getCredentials(function (err) {
        if (err) {
          callback(err);
        }

        callback(null, finalizePost());
      });
    } else {
      return finalizePost();
    }
  }
function createPresignedPost ( params , callback ) { if ( typeof params === 'function' && callback === undefined ) { callback = params ; params = null ; } params = AWS . util . copy ( params || { } ) ; var boundParams = this . config . params || { } ; var bucket = params . Bucket || boundParams . Bucket , self = this , config = this . config , endpoint = AWS . util . copy ( this . endpoint ) ; if ( ! config . s3BucketEndpoint ) { endpoint . pathname = '/' + bucket ; } function finalizePost ( ) { return { url : AWS . util . urlFormat ( endpoint ) , fields : self . preparePostFields ( config . credentials , config . region , bucket , params . Fields , params . Conditions , params . Expires ) } ; } if ( callback ) { config . getCredentials ( function ( err ) { if ( err ) { callback ( err ) ; } callback ( null , finalizePost ( ) ) ; } ) ; } else { return finalizePost ( ) ; } }
Get a pre-signed POST policy to support uploading to S3 directly from an
HTML form.

@param params [map]
@option params Bucket [String]     The bucket to which the post should be
uploaded
@option params Expires [Integer]   (3600) The number of seconds for which
the presigned policy should be valid.
@option params Conditions [Array]  An array of conditions that must be met
for the presigned policy to allow the
upload. This can include required tags,
the accepted range for content lengths,
etc.
@see http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html
@option params Fields [map]        Fields to include in the form. All
values passed in as fields will be
signed as exact match conditions.
@param callback [Function]

@note All fields passed in when creating presigned post data will be signed
as exact match conditions. Any fields that will be interpolated by S3
must be added to the fields hash after signing, and an appropriate
condition for such fields must be explicitly added to the Conditions
array passed to this function before signing.

@example Presiging post data with a known key
var params = {
Bucket: 'bucket',
Fields: {
key: 'key'
}
};
s3.createPresignedPost(params, function(err, data) {
if (err) {
console.error('Presigning post data encountered an error', err);
} else {
console.log('The post data is', data);
}
});

@example Presigning post data with an interpolated key
var params = {
Bucket: 'bucket',
Conditions: [
['starts-with', '$key', 'path/to/uploads/']
]
};
s3.createPresignedPost(params, function(err, data) {
if (err) {
console.error('Presigning post data encountered an error', err);
} else {
data.Fields.key = 'path/to/uploads/${filename}';
console.log('The post data is', data);
}
});

@note You must ensure that you have static or previously resolved
credentials if you call this method synchronously (with no callback),
otherwise it may not properly sign the request. If you cannot guarantee
this (you are using an asynchronous credential provider, i.e., EC2
IAM roles), you should always call this method with an asynchronous
callback.

@return [map]  If called synchronously (with no callback), returns a hash
with the url to set as the form action and a hash of fields
to include in the form.
@return [null] Nothing is returned if a callback is provided.

@callback callback function (err, data)
@param err [Error] the error object returned from the policy signer
@param data [map] The data necessary to construct an HTML form
@param data.url [String] The URL to use as the action of the form
@param data.fields [map] A hash of fields that must be included in the
form for the upload to succeed. This hash will
include the signed POST policy, your access key
ID and security token (if present), etc. These
may be safely included as input elements of type
'hidden.'
Get a pre - signed POST policy to support uploading to S3 directly from an HTML form .