Express middleware to designed to make streaming image uploads to s3 easy. This module has the following functionality:
- Streaming file uploads or remote file urls to s3.
- Resize images on the fly, storing multiple images sizes at once.
- Customize JSON error messages.
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);
});
type: string
default: An unknown error occurred: {{message}}
The error to display if an unexpected error occurrs.
type: integer
default: 500
The status code to return if an unexpected error occurrs.
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.
type: integer
default: 500
The status code to return if there was a problem using graphicsmagick to resize the image.
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.
type: integer
default: 500
The status code to return if there was a problem uploading the image to s3.
type: string
default: empty
Your s3 access key id.
type: string
default: empty
Your s3 secret access key.
type: string
default: empty
The s3 bucket where the iamges should be uploaded
type: string
default: empty
The ACL permissions of uploaded files. Available options can be found here.
type: integer
default: 10485760
Specifies what the chunk size (also referred to as the part size) should be for uploads.
type: integer
default: 10485760
Specifies the number of s3 tasks that should run concurrently.
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.
type: string
default: body
Specifies the request property where the url key can be found. Possible values are body, query and params.
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.