Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Replace Knox with aws-sdk #35

Merged
merged 25 commits into from
Jun 18, 2018
Merged

Conversation

mikehazell
Copy link
Contributor

@mikehazell mikehazell commented Jun 15, 2018

Overview

The Knox library which this package was previously based on has gone unmaintained for some time and is now failing in many scenarios. This version replaces Knox with the official AWS Javascript SDK.

Breaking changes

The option headers has been replaced with uploadParams. If you were setting custom headers with previous version of the S3 Storage Adapter you will need to change these to use the appropriate param as defined in the AWS Documentation

For example, { headers: { 'x-amz-acl': 'public-read' } } should now be { uploadParams: { ACL: 'public-read' } }.

Additions

  • publicUrl: You can now customise the public url by passing either a domain name as a string (eg. { publicUrl: "https://xxxxxx.cloudfront.net" }) or by passing a function which takes the file object and returns a the url as a string.
{ publicUrl: file => `https://xxxxxx.cloudfront.net${file.path}/${file.filename}` }

Other

  • path: The requirement for path to have a leading slash has been removed. The previous implementation failed to catch this miss-configuration and Knox helpfully made the file uploads work anyway. This has lead to a situation where it is possible/likely that there are existing installations where a miss-configured path is stored in the database. To avoid breaking these installs we now handle adding or removing the leading slash as required.

Thanks

Thanks to @aaronfranco, @stevenkaspar, @alsoicode and @sktt who all had a go at this refactor before me. I have borrowed heavily from all of your work.

@alsoicode
Copy link

+1 for this. Nice work.

Copy link
Contributor

@dominikwilkowski dominikwilkowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome, Thanks @mikehazell; love the comments!

index.js Outdated
var s3options = assign({}, this.options, { bucket: file.bucket });
return knox.createClient(s3options);
S3Adapter.prototype._resolveBucket = function (file) {
if (file && file.bucket && file.bucket) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably don't need file.bucket twice here?

@@ -10,8 +10,8 @@
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should version bump the package no? "version": "2.0.0", on line 3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants