Skip to content

Commit

Permalink
Presigned url headers (#70)
Browse files Browse the repository at this point in the history
* Added example to s3.putObject()

* Added headers to pre-signed urls

---------

Co-authored-by: John Wilson <[email protected]>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: John Berquist <[email protected]>
  • Loading branch information
4 people authored Mar 30, 2023
1 parent fef9e96 commit 78d724e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions services/s3.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ component {
/**
* returns a pre-signed URL that can be used to access an object
* http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html
* https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html (Overriding Response Header Values)
* queryParams = { "response-content-disposition": "attachment" } is useful for forcing a download
* @Bucket The name of the bucket containing the object
* @ObjectKey The object key
* @Expires The length of time in seconds for which the url is valid
Expand All @@ -565,22 +567,23 @@ component {
required string Bucket,
required string ObjectKey,
numeric Expires = 300,
string VersionId = ''
string VersionId = '',
struct queryParams = {}
) {
var requestSettings = api.resolveRequestSettings( argumentCollection = arguments );
var host = getHost( requestSettings );
var path = arguments.Bucket.find( '.' ) ? '/' & arguments.Bucket : '';
path &= '/' & ObjectKey;
var queryParams = { };
if ( len( arguments.VersionId ) ) queryParams[ 'versionId' ] = arguments.VersionId;
path &= '/' & arguments.ObjectKey;

if ( len( arguments.VersionId ) ) arguments.queryParams.append({ "versionId": arguments.VersionId });

return api.signedUrl(
variables.service,
host,
requestSettings.region,
'GET',
path,
queryParams,
arguments.queryParams,
Expires,
requestSettings.awsCredentials,
false
Expand All @@ -602,6 +605,9 @@ component {
* @Metadata Used to store user-defined metadata. Struct keys are prefixed with 'x-amz-meta-' and sent as headers in the put request.
* @StorageClass The storage class for the file. Valid values: STANDARD | STANDARD_IA | REDUCED_REDUNDANCY
* @WebsiteRedirectLocation If the bucket is configured as a website, redirects requests for this object to another object in the same bucket or to an external URL.
*
* Example: aws.s3.putObject( 'your-bucket-name', 'filename.ext', fileReadBinary( pathToFile ), '', '', '', fileGetMimeType( pathToFile ) )
* https://github.com/jcberquist/aws-cfml/issues/25
*/
public any function putObject(
required string Bucket,
Expand Down

0 comments on commit 78d724e

Please sign in to comment.