# @coatilabs/keystone-fs-image-storage-adapter

> Storage Adapter to help you to manage an Image document with Jimp tool

Latest version **1.0.4** (published 2018-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @coatilabs/keystone-fs-image-storage-adapter
pnpm add @coatilabs/keystone-fs-image-storage-adapter
yarn add @coatilabs/keystone-fs-image-storage-adapter
bun add @coatilabs/keystone-fs-image-storage-adapter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-09-11 |
| First published | 2018-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 11.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | coatilabs |
| Maintainers | jupazave |

## Links

- npm: https://www.npmjs.com/package/@coatilabs/keystone-fs-image-storage-adapter
- Repository: https://github.com/coatilabs/keystone-fs-image-storage-adapter
- Homepage: https://github.com/coatilabs/keystone-fs-image-storage-adapter#readme
- Issues: https://github.com/coatilabs/keystone-fs-image-storage-adapter/issues
- npm.io page: https://npm.io/package/@coatilabs/keystone-fs-image-storage-adapter

## Dependencies (7)

- [url](https://npm.io/package/url.md) ^0.11.0
- [jimp](https://npm.io/package/jimp.md) ^0.2.28
- [debug](https://npm.io/package/debug.md) ^4.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^5.0.0
- [object-assign](https://npm.io/package/object-assign.md) ^4.1.1
- [sanitize-filename](https://npm.io/package/sanitize-filename.md) ^1.6.1
- [keystone-storage-namefunctions](https://npm.io/package/keystone-storage-namefunctions.md) ^1.1.1

## Recent versions

- 1.0.4 (latest) — 2018-09-11
- 1.0.3 — 2018-08-30
- 1.0.2 — 2018-08-30
- 1.0.0 — 2018-02-09

## README

# Jimp based image storage adapter for KeystoneJS

This adapter is designed to manipulate images after upload with [Jimp](https://github.com/oliver-moran/jimp) tool in KeystoneJS using the storage API.

Tested in Node.js 6.12.2

## Usage

Configure the storage adapter:

```js

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:

```js
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`](http://npm.im/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`](https://github.com/oliver-moran/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).

```JS
{
    filename: String,
}
```


# License

Licensed under the standard MIT license. See [LICENSE](license).

---
_Source: https://npm.io/package/@coatilabs/keystone-fs-image-storage-adapter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
