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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zachtrice/lambda-image-upload

v0.1.0

Published

Parse a multipart image upload in an AWS Lambda (API Gateway), transform it with sharp, and store it to S3. Small, composable, dependency-light helpers.

Readme

@zachtrice/lambda-image-upload

Small, composable helpers to accept an image upload inside an AWS Lambda (behind API Gateway), transform it with sharp, and store it on S3.

  • Parse multipart/form-data straight from an API Gateway proxy event (handles the base64 body).
  • Auto-rotate (EXIF), resize to a bounding box, and re-encode (WebP by default).
  • Put to S3 using your SDK client, so this package never bundles aws-sdk.
  • Zero framework assumptions. Use the one-shot helper, or the small pieces.

Install

npm install @zachtrice/lambda-image-upload

busboy and sharp are dependencies. @aws-sdk/client-s3 is an optional peer (the Node 18+ Lambda runtime already ships the v3 SDK, so you usually get it for free).

Quick start (one-shot)

const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3')
const crypto = require('crypto')
const { handleImageUpload } = require('@zachtrice/lambda-image-upload')

const s3 = new S3Client({})

exports.handler = async (event) => {
  try {
    const { key } = await handleImageUpload(event, {
      field: 'image',
      bucket: process.env.UPLOAD_BUCKET,
      s3Client: s3,
      PutObjectCommand,
      maxBytes: 12 * 1024 * 1024,
      process: { maxWidth: 1400, maxHeight: 1400, format: 'webp', quality: 82 },
      keyFor: ({ ext }) => `uploads/${crypto.randomUUID()}.${ext}`
    })
    return { statusCode: 201, body: JSON.stringify({ key }) }
  } catch (err) {
    const status = err.code === 'TOO_LARGE' ? 413 : (err.code ? 400 : 500)
    return { statusCode: status, body: JSON.stringify({ error: err.message }) }
  }
}

Use the pieces

const {
  parseMultipart, // (event, { limits }) -> { files, fields }
  processImage,   // (buffer, opts) -> { buffer, format, contentType, width, height }
  uploadToS3      // ({ client, PutObjectCommand, bucket, key, body, contentType }) -> ...
} = require('@zachtrice/lambda-image-upload')

const { files } = await parseMultipart(event, { limits: { files: 1, fileSize: 12e6 } })
const out = await processImage(files.image.buffer, { maxWidth: 1600, format: 'webp' })
await uploadToS3({ client: s3, PutObjectCommand, bucket, key, body: out.buffer, contentType: out.contentType })

API

handleImageUpload(event, options)

Parse, validate, transform, and store in one call. Returns { key, contentType, bytes }.

| option | type | default | notes | | --- | --- | --- | --- | | field | string | 'image' | Multipart field name to read. | | bucket | string | — | Required. | | keyFor | ({ filename, mimeType, ext }) => string | — | Required. Builds the S3 object key. | | s3Client | S3Client | — | Required. | | PutObjectCommand | class | — | Required. | | process | ProcessImageOptions | {} | Passed to processImage. | | cacheControl | string | public, max-age=31536000 | | | maxBytes | number | — | Reject larger files (TOO_LARGE). |

Throws errors with a stable code: NO_FILE, TOO_LARGE, NOT_IMAGE.

parseMultipart(event, { limits })

Returns { files, fields }. Each file is { filename, mimeType, buffer, truncated }.

processImage(buffer, options)

{ maxWidth, maxHeight, format='webp', quality=82, rotate=true, withoutEnlargement=true, fit='inside' } → { buffer, format, contentType, width, height }.

uploadToS3({ client, PutObjectCommand, bucket, key, body, contentType, cacheControl })

Thin PutObject wrapper. You provide the client + command class.

API Gateway note

Add multipart/form-data to your API's binary media types so the body arrives base64-encoded (event.isBase64Encoded === true). This library decodes it for you.

License

MIT © ZachTRice