0.0.5 • Published 5 years ago

painless-image-upload v0.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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.

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago