1.0.4 • Published 6 years ago

@coatilabs/keystone-fs-image-storage-adapter v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Jimp based image storage adapter for KeystoneJS

This adapter is designed to manipulate images after upload with Jimp tool in KeystoneJS using the storage API.

Tested in Node.js 6.12.2

Usage

Configure the storage adapter:

var storage = new keystone.Storage({
    adapter: require('keystone-fs-image-storage-adapter'),
    imagefs: {
        path: keystone.expandPath('./uploads'), // required; path where the files should be stored
        publicPath: '/uploads', // path where files will be served,
        manageImage: function(file, callback) {
            // Here you can manipulate file
            callback(null, file);
        }
    }
});

Then use it as the storage provider for a File field:

File.add({
  name: { type: String },
  file: { type: Types.File, storage: storage },
});

Options

The adapter requires an additional imagefs field added to the storage options. it accepts the following values:

  • path: (string; required) Path the files will be stored at on disk

  • generateFilename: (function; default: random filename) Method to generate a filename for the uploaded file. Gets passed the file data, the attempt number and the callback to call with the filename.

    • See keystone-storage-namefunctions for additional filename generators, including content hash filename and original filename. See its source for more information on how to write your own.
  • manageImage: (function; default: copies same file) Method to manipulate your image file

    • See Jimp for additional documentation.
  • whenExists: (string; default: 'retry') Specifies what to do when the file exists already. Can be one of 'retry', 'error' or 'overwrite'.

  • retryAttempts: (number; default: 3) If whenExists is set to 'retry', how many times keystone should try to generate a unique filename before returning an error

  • publicPath: (string) Optional path the files will served from by the webserver

Schema

The FS adapter supports all the default Keystone file schema fields. It also additionally supports and enables the filename path (required).

{
    filename: String,
}

License

Licensed under the standard MIT license. See LICENSE.