README
skipper-s3-resizer
This is extended skipper-s3-resizer based on - Original skipper-s3-resize
New features
Adds optional configurations:
prefix
- S3 object prefix (Default:''
)filename
- Custom function for naming files to be uploaded (Default:<uuid>.<ext>
).stretch
- Whether to stretch or cover image (Default:false
).
Changed resizing technique:
- If width and height are not specified, image will be uploaded in original size
- If only one dimension is specified, downscale (keeps aspect-ratio)
- If both dimensions are specified
- And
stretch == true
, downscale (breaking aspect-ratio) - And
stretch == false
, downscale ([cover] (https://github.com/paolochiodi/resizer#cover))
- And
Based on SailsJS Skipper S3 adapter for receiving upstreams with a twist: Images will be resized before uploading using GraphicMagick.
Installation
Make sure you have graphicmagick installed.
Make sure you have skipper itself installed as your body parser. This is the default configuration in Sails as of v0.10.
Run in your console:
npm install skipper-s3-resizer --save
Usage
- In Controller:
upload: function(req, res) {
req.file('image').upload({
adapter: require('skipper-s3-resizer'), // Required
key: <YOUR_S3_ACCESS_KEY>, // Required
secret: <YOUR_S3_SECRET_KEY>, // Required
bucket: <YOUR_S3_BUCKET>, // Required
prefix: 'prefixed',
filename: function (base, ext) {
return sails.shortid.generate().concat(ext);
},
resize: {
stretch: false,
width: <WIDTH>,
height: <HEIGHT>
},
headers: {
'x-amz-acl': 'public-read'
}
}, function(err, uploadedFiles) {
if(err) return res.serverError(err);
res.ok();
});
}
More info about headers: