Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/aws/s3.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ const { s3 } = aws;

const url = await s3.getSignedDownloadUrl( 'my-bucket', 'my/key.json', 360 );
console.log( url );

// With native args
const url = await s3.getSignedDownloadUrl( 'my-bucket', 'my/key.json', 360, { ResponseContentDisposition: 'attachment; filename="key.json"' } );
console.log( url );
```

#### Arguments
Expand All @@ -213,6 +217,7 @@ console.log( url );
|bucket|String|The the s3 bucket of the object to download||
|key|String|The the s3 key of the object to download||
|expiration|number|The number of seconds before the presigned URL expires||
|nativeArgs|Object|All `client-s3` SDK [GetObjectCommand arguments](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-s3/Class/GetObjectCommand/) except `Key` and `Bucket`, which are defined by the previous arguments||

#### Return

Expand Down
8 changes: 6 additions & 2 deletions src/aws/s3/get_signed_download_url.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { GetObjectCommand } from '@aws-sdk/client-s3';

export const getSignedDownloadUrl = async ( client, bucket, key, expiration ) => {
const getObjectCmd = new GetObjectCommand( { Bucket: bucket, Key: key } );
export const getSignedDownloadUrl = async ( client, bucket, key, expiration, nativeArgs ) => {
const getObjectCmd = new GetObjectCommand( {
...nativeArgs,
Bucket: bucket,
Key: key
} );
const url = await getSignedUrl( client, getObjectCmd, { expiresIn: expiration } );
return url;
};
13 changes: 13 additions & 0 deletions src/aws/s3/get_signed_download_url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,17 @@ describe( 'S3 Get Signed Download Url Spec', () => {
strictEqual( getSignedUrlMock.mock.calls.length, 1 );
deepStrictEqual( getSignedUrlMock.mock.calls[0].arguments, [ client, commandInstance, { expiresIn: expiration } ] );
} );

it( 'Should get a signed download url for a file from S3 with native args and return its content', async () => {
getSignedUrlMock.mock.mockImplementation( () => response );

const contentDisposition = 'attachment; filename="key"';
const result = await getSignedDownloadUrl( client, bucket, key, expiration, { ResponseContentDisposition: contentDisposition } );

strictEqual( result, response );
strictEqual( constructorMock.mock.calls.length, 1 );
deepStrictEqual( constructorMock.mock.calls[0].arguments[0], { Key: key, Bucket: bucket, ResponseContentDisposition: contentDisposition } );
strictEqual( getSignedUrlMock.mock.calls.length, 1 );
deepStrictEqual( getSignedUrlMock.mock.calls[0].arguments, [ client, commandInstance, { expiresIn: expiration } ] );
} );
} );