painless-image-upload

0.0.5Β β€’Β PublicΒ β€’Β Published

painless-image-upload

Easy to use yet highly customizable image upload route, just mount it to your express application πŸ™Œ!

Quick Start

$ npm install --save painless-image-upload
$ mkdir images # Default image upload folder, you can configure this later.
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const painless = require('painless-image-upload');
app.use(bodyParser.json());

app.use('/painless', painless.router);

// πŸ™Œ Horray! You now have an image upload endpoint.

Usage

Now you can simply POST { "base64": YOUR BASE 64 IMAGE } to /painless/upload.

It will return something like the following:

{
    "100": "af09af68-c305-40f3-b954-b06958d737aa-100.png",
    "500": "af09af68-c305-40f3-b954-b06958d737aa-500.png",
    "1000": "af09af68-c305-40f3-b954-b06958d737aa-1000.png"
}

Configurations

To modify configurations, use painless.config variable.

imageIdGenerator: () => string

A function used to generate image ID, by default it simply returns uuid-v4. You can customize this anyway you like, as long as every ID is unique.

bodyNormalizer: (body) => { base64: string }

Takes in express req.body, and normalizes it to {base64: string} format.

By default it simply returns req.body.

For example, if you wish user to pass the base64 string in image field. You would make bodyNormalizer the following:

painless.config.bodyNormalizer = function(body) {
    return {
        base64: body.image,
    }
}

pathBuilder: (imageName: string) => string

Takes in the image file name, returns its real path, by default, this function just returns the imageName.

sizes: number[]

List of sizes you wish to save, default values are 100, 500 and 1000.

outputPath: string

Output directory for all images, default ./images.

Readme

Keywords

none

Package Sidebar

Install

npm i painless-image-upload

Weekly Downloads

1

Version

0.0.5

License

MIT

Unpacked Size

16.7 kB

Total Files

16

Last publish

Collaborators

  • junthehacker