Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Expose the second argument to S3's upload()
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed Oct 13, 2015
1 parent ddad5d3 commit 8673cd8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ You upload the files as usual with any other adapter. See some examples below.

#### Supported options

| Option | Type | Details |
|------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| key | String | Your Amazon access key |
| secret | String | Your Amazon secret |
| bucket | String | The S3 bucket to upload the file to |
| s3options | Object | Optional options to be passed to the underlying Amazon SDK library when performing the file upload. This could be any parameter that is supported by the S3's [`putObject()`][s3-putobject] method. |
| onProgress | Function | Marked by Skipper core as experimental. If provided, will be called periodically as the data is being uploaded with current progress information. |
| Option | Type | Details |
|------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| key | String | Your Amazon access key |
| secret | String | Your Amazon secret |
| bucket | String | The S3 bucket to upload the file to |
| s3params | Object | Optional parameters to be passed to the underlying Amazon SDK library when performing the file upload. This could be any parameter that is supported by the S3's [`upload()`][s3-upload] method. |
| s3options | Object | Optional configuration for the upload request to be passed to the underlying Amazon SDK library. This could be any parameter that is supported by the second argument of the [`upload()`][s3-upload] method. |
| onProgress | Function | Marked by Skipper core as experimental. If provided, will be called periodically as the data is being uploaded with current progress information. |

#### Example usage

Expand All @@ -48,9 +49,9 @@ const options =
, key: 'somekeyhere'
, secret: 'dontsharethis'
, bucket: 'my-s3-bucket'
// Let's use the custom s3options to upload this file as publicly
// Let's use the custom s3params to upload this file as publicly
// readable by anyone
, s3options:
, s3params:
{ ACL: 'public-read'
}
// And while we are at it, let's monitor the progress of this upload
Expand Down Expand Up @@ -144,7 +145,7 @@ This is great, because it allows your clients to interact with your S3 storage d

```js
// Assuming you already have an adapter instance...
const url = adapter.url('getObject', { s3options: { Key: 'avatars/123.jpg' } })
const url = adapter.url('getObject', { s3params: { Key: 'avatars/123.jpg' } })
// Give the url to the client - they can read this file directly from there
// Optionally do a redirect (303 - "see other") to this file yourself:
// res.redirect(303, url)
Expand Down Expand Up @@ -172,4 +173,4 @@ This software is licensed under the **BSD-3-Clause License**. See the [LICENSE](
[npm-url]: https://npmjs.org/package/skipper-better-s3
[skipper-logo]: http://i.imgur.com/P6gptnI.png
[project-root]: https://github.com/Dreamscapes/skipper-better-s3
[s3-putobject]: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property
[s3-upload]: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property
17 changes: 12 additions & 5 deletions lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ module.exports = class Adapter {
, request:
{ Bucket: opts.bucket || defaults.request.Bucket
}

, options: opts.s3options || {}
}

config.request = merge(config.request)
.and(opts.s3options || {})
.and(opts.s3params || {})
.excluding('s3options')
.into({})

return config
Expand Down Expand Up @@ -172,7 +175,7 @@ module.exports = class Adapter {
* @param {String?} opts.key S3 access key
* @param {String?} opts.secret S3 access secret
* @param {String?} opts.bucket S3 bucket to use for this operation
* @param {Object?} opts.s3options Optional object to provide additional options
* @param {Object?} opts.s3params Optional object to provide additional options
* for the signed request. The options can be
* anything that is supported by the given S3's
* operation.
Expand Down Expand Up @@ -219,12 +222,16 @@ module.exports = class Adapter {
* @param {String?} opts.bucket S3 bucket to upload to
* @param {Adapter.onProgress?} opts.onProgress Function to be called repeatedly as the
* upload progresses
* @param {Object?} opts.s3options Optional object to provide additional
* @param {Object?} opts.s3params Optional object to provide additional
* options for the upload request. The options
* can be anything that is supported by S3's
* `putObject()` method.
* `upload()` method.
* @param {Object?} opts.s3options Optional object to further configure the
* upload request. This is passed directly to
* the S3's `upload()` method as second
* parameter.
*
* @see http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property
* @see http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property
* @return {Uploader}
*/
receive (opts) {
Expand Down
2 changes: 1 addition & 1 deletion lib/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = class Uploader extends WritableStream {
.excluding('onProgress')
.into({})

, request = scope.client.upload(params, (err, data) => {
, request = scope.client.upload(params, scope.opts.options, (err, data) => {
// Attach the response data to the stream - Skipper packages this in its response to the
// caller for further reuse
inStream.extra = data
Expand Down

0 comments on commit 8673cd8

Please sign in to comment.