npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@exio.tech/upload-multipart-image

v2.0.5

Published

Upload images and text-fields with multipart/form-data and express.js

Downloads

6

Readme

UploadMultipartImage

Description

A node.js module for handling uploaded images and text fields with multipart/form-data for express.js.

Requirements

Usage

const path = require('path')

const uploadImage = require('@exio.tech/upload-multipart-image')
const express = require('express')


const ROOT_DIR = require.main.path

const app = express()

app.get('/', (req, res, next) => {
    res.send(`
    <html>
    <head></head>
    <body>
    <form method="POST" enctype="multipart/form-data">
        <input type="text" name="textfield"><br />
        <input type="file" name="imagefield"><br />
        <input type="submit">
    </form>
    </body>
    </html>
    `)
})

app.post('/', uploadImage({
    imageFieldNames: 'imagefield', // OR multiple - ['image1', 'image2']
    destination: (fileInfo) => path.join(ROOT_DIR, './images'),
    filename: (fileInfo) => fileInfo.defaultFilename + '.png',
    sharp: (fileInfo) => fileInfo.defaultSharp.rotate(140).resize(400, 400).png(),
}), (req, res, next) => {
    res.send(req.file)
})

app.listen(8000, (err) => {
    if (err) return console.log(err)
    console.log('Server started successfully')
})

Key | Description | Default ---| ---| ---| imageFieldNames? | Defines which image fieldnames your application expects. If any expected, then if not expected image fields encountered before all expected ones are processed, error will be fired, if nothing expeted, then any files will be simply thrown away | [], i.e. images will thrown away required? | Defines subset of imageFieldNames which are required, or boolean which indicates if all provided imageFieldNames are required | true destination? | Defines folder path where to save uploaded images | os.tmpdir() filename? | Defines filename to save image with (extension included) | uuidv4() sharp? | Defines function which MUST return new Instance of sharp to process images | sharp() imageMaxSize? | Defines Max Size in bytes for image fields, Details and Default See - BusBoy limits:fileSize fieldNameSize? | Defines fieldnames Max Size in bytes, Details and Default See - BusBoy limits:fieldNameSize fieldSize? | Defines non-image field value Max Size in bytes, Details and Default See - BusBoy limits:fieldSize fields? | Defines non-image fields Max count, Details and Default See - BusBoy limits:fields

If imageFieldNames is an array of convertables to strings, then files metadata will be provided with req.files, if it is a string, then it will be provided with req.file.

You can omit imageFieldNames property, set it to null or empty_array, then images will be simply thrown away, and middleware will act as simle text field handler.

Other details see in TSDocs.