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

s3-image-middleware

v2.0.1

Published

Express middleware to resize images and upload them to s3

Downloads

6

Readme

s3 image middleware

Express middleware to designed to make streaming image uploads to s3 easy. This module has the following functionality:

  1. Streaming file uploads or remote file urls to s3.
  2. Resize images on the fly, storing multiple images sizes at once.
  3. Customize JSON error messages.

Example

let config = {
	s3: {
		accessKeyId: 'access key id goes here',
		secretAccessKey: 'secret access key goes here',
		params: {
			Bucket: 'my-bucket',
			ACL: 'public-read'
		},
		options: {
			partSize: 10 * 1024 * 1024,
			queueSize: 1
		}
	},
	url: {
		key: 'picture',
		type: 'body'
	},
	sizes: [
		{ name: 'original', width: null, height: null },
		{ name: 'medium', width: 1020, height: 760 }
	]
};

let s3ImageMiddleware = require('s3-image-middleware')(imageConfig);

router.post('/image', s3ImageMiddleware, function(req, res, next) {
	console.log(req.s3Images);
	// {
	// 	filename: 'profile.jpg',
	// 	sizes: {
	// 		original: { width: null, height: null, location: '... image url ...' },
	// 		medium: { width: 1020, height: 760, location: '... image url ...' },
	// 	}
	// }
	res.json(req.s3Images);
});

Options

errors

errors.UNKNOWN.message

type: string

default: An unknown error occurred: {{message}}

The error to display if an unexpected error occurrs.

errors.UNKNOWN.status

type: integer

default: 500

The status code to return if an unexpected error occurrs.

errors.IMAGE_RESIZE.message

type: string

default: There was an error resizing the image: {{message}}

The error to display if there was a problem using graphicsmagick to resize the image.

errors.IMAGE_RESIZE.status

type: integer

default: 500

The status code to return if there was a problem using graphicsmagick to resize the image.

errors.S3_UPLOAD.message

type: string

default: There was an error saving the image: {{message}}

The error to display if there was a problem uploading the image to s3.

errors.S3_UPLOAD.status

type: integer

default: 500

The status code to return if there was a problem uploading the image to s3.

s3

s3.accessKeyId

type: string

default: empty

Your s3 access key id.

s3.secretAccessKey

type: string

default: empty

Your s3 secret access key.

s3.params.Bucket

type: string

default: empty

The s3 bucket where the iamges should be uploaded

s3.params.ACL

type: string

default: empty

The ACL permissions of uploaded files. Available options can be found here.

s3.options.partSize

type: integer

default: 10485760

Specifies what the chunk size (also referred to as the part size) should be for uploads.

s3.options.queueSize

type: integer

default: 10485760

Specifies the number of s3 tasks that should run concurrently.

url

url.key

type: string

default: url

Specifies the key where a url in the request can be found. The middleware will download the file from this url (if provided) and upload it to s3.

url.type

type: string

default: body

Specifies the request property where the url key can be found. Possible values are body, query and params.

sizes

sizes

type: array of objects

default: []

Specifies the size of files that should be uploaded to s3. Each object in the array should have three properties: name, width and height. Name is a label for this particular size so that it can be referenced in the future. Width and height specify the max width and height that images should be scaled to. Images will not be distorted. Instead they will be as large as possible while still fitting within the specified width and height dimensions.