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

Commit

Permalink
Updating usage and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JedWatson committed Aug 9, 2016
1 parent 8f232ae commit d39a6ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(The MIT License)

Copyright (c) 2016 Joseph Gentle + contributors
Copyright (c) 2016 Joseph Gentle, Jed Watson and contributors

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
37 changes: 15 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,45 @@

This adapter is designed to replace the existing `S3File` field in KeystoneJS using the new storage API.

This project contains the keystone S3 file adapter. This adapter replaces the existing S3 file field, using the new keystone storage adapter class.
Compatible with Node.js 0.12+

## Usage

Configure the storage adapter:

```javascript
```js
var storage = new keystone.Storage({
adapter: require('keystone-storage-adapter-s3'),
s3: {
key: process.env.S3_KEY, // these 3 settings all default to these environment variables
secret: process.env.S3_SECRET,
bucket: process.env.S3_BUCKET,
key: 's3-key', // required; defaults to process.env.S3_KEY
secret: 'secret', // required; defaults to process.env.S3_SECRET
bucket: 'mybucket', // required; defaults to process.env.S3_BUCKET
path: '/profilepics',
defaultHeaders: {
'x-amz-acl': 'public-read', // Etc. See docs for details
'x-amz-acl': 'public-read', // add default headers; see below for details
},
},
schema: {
url: true, // optional - generate & store a public URL
etag: true, // optional - store the etag for the resource
path: true, // optional - store the path and bucket in your db. See below.
bucket: true,
bucket: true, // optional; store the bucket the file was uploaded to in your db
etag: true, // optional; store the etag for the resource
path: true, // optional; store the path of the file in your db
url: true, // optional; generate & store a public URL
},
});
```

Then use it in your file type:
Then use it as the storage provider for a File field:

```javascript
```js
File.add({
name: { type: String },
file: { type: Types.File, storage: storage, required: true, initial: true },
file: { type: Types.File, storage: storage },
});
```

### Options:

The adapter requires an additional `s3` field added to the storage options. Only `key`, `secret` and `bucket` are required.

It accepts the following values:
The adapter requires an additional `s3` field added to the storage options. It accepts the following values:

- **key**: *(required)* AWS access key. Configure your AWS credentials in the [IAM console](https://console.aws.amazon.com/iam/home?region=ap-southeast-2#home).

Expand All @@ -61,18 +59,13 @@ It accepts the following values:

The S3 adapter supports all the standard Keystone file schema fields. It also supports storing the following values per-file:

- **path, bucket**: The path and bucket at which the file is stored in the database. If these are present when reading or deleting files, they will be used instead of looking at the global S3Adapter configuration. The effect of this is that you can have some (eg, old) files in your collection stored in different bucket / different path inside your bucket.
- **bucket**, **path**: The bucket, and path within the bucket, for the file can be is stored in the database. If these are present when reading or deleting files, they will be used instead of looking at the adapter configuration. The effect of this is that you can have some (eg, old) files in your collection stored in different bucket / different path inside your bucket.

The main use of this is to allow slow data migrations. If you *don't* store these values you can arguably migrate your data more easily - just move it all, then reconfigure and restart your server.

- **etag**: The etag of the stored item. This is equal to the MD5 sum of the file content.


# Migrating from keystone 0.3

The fields have been structured to make the new type mostly-compatible with the old keystone s3 field field. The only difference is that `filetype` has been renamed to `mimetype`.


# License

Licensed under the standard MIT license. See [LICENSE](license).
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// The keystone S3 adapter class. See README.md for usage.
// This class is a simple wrapper around knox
var knox = require('knox');

var pathlib = require('path');
Expand All @@ -15,13 +13,15 @@ var defaultS3Options = {

// This constructor is usually called indirectly by the Storage class in
// keystone.

// S3-specific options should be specified in an `options.s3` field, which can
// contain the following options: { key, secret, bucket, region, defaultHeaders,
// style, path }.
//

// The schema can contain the additional fields { path, bucket, etag }.
//

// See README.md for details and usage examples.

function S3Adapter (options, schema) {
var s3Options = assign({}, defaultS3Options, options.s3);
this.options = assign({}, options, { s3: s3Options });
Expand Down

0 comments on commit d39a6ce

Please sign in to comment.