Skip to content

Keystone Storage Adapter to help you to manage an image document with Jimp tool

License

Notifications You must be signed in to change notification settings

coatilabs/keystone-fs-image-storage-adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Keystone Storage Adapter to help you to manage an image document with Jimp tool

Resources

License

Stars

Watchers

Forks

Packages