Flexible and efficient resize, rename, and upload images to Amazon S3 disk storage. Uses the official AWS Node SDK and GM for image processing.
npm install s3-uploader --save
- Node.JS >= v0.10
- imagemagic
- AWS credentials environment variables
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
var Upload = require('s3-uploader');
- string
awsBucketName
- name of Amazon S3 bucket - object
opts
- global upload options-
number
resizeQuality
- thumbnail resize quallity (default70
) -
boolean
returnExif
- return exif data for original image (defaultfalse
) -
string
tmpDir
- directory to store temporary files (defaultos.tmpdir()
) -
number
workers
- number of async workers (default1
) -
string
url
- custom public url (default build fromregion
andawsBucketName
) -
object
aws
- AWS SDK configuration optsion- string
region
- region for you bucket (defaultus-east-1
) - string
path
- path within your bucket (default""
) - string
acl
- default ACL for uploded images (defaultprivat
) - string
accessKeyId
- AWS access key ID override - string
secretAccessKey
- AWS secret access key override
- string
-
The
aws
object is passed directly toaws-sdk
. You can add any of these options in order to fine tune the connection – if you know what you are doing.
- object[]
versions
- versions to upload to S3- boolean
original
- set this totrue
to save the original image - string
suffix
- this is appended to the file name (default""
) - number
quality
- resized image quality (defaultresizeQuality
) - number
maxWidth
- max width for resized image - number
maxHeight
- max height for resized image
- boolean
var client = new Upload('my_s3_bucket', {
awsBucketRegion: 'us-east-1',
awsBucketPath: 'images/',
awsBucketAcl: 'public-read',
versions: [{
original: true
},{
suffix: '-large',
quality: 80,
maxHeight: 1040,
maxWidth: 1040,
},{
suffix: '-medium',
maxHeight: 780,
maxWidth: 780
},{
suffix: '-small',
maxHeight: 320,
maxWidth: 320
}]
});
-
string
src
- absolute path to source image to upload -
object
opts
- upload config options- string
awsPath
- local override foropts.aws.path
- string
-
function
cb
- callback function (Errorerr
, object[]versions
, objectmeta
)- Error
err
-null
if everything went fine - object[]
versions
- original and resized images with path/location - object
meta
- metadata for original image
- Error
client.upload('/some/file/path.jpg', {}, function(err, images, meta) {
if (err) {
console.error(err);
} else {
for (var i = 0; i < images.length; i++) {
console.log('Thumbnail with width %i, height %i, at %s', images[i].width, images[i].height, images[i].url);
}
}
});
A
+-- B
`-- C
`-- D
`-- E
Where A is the original image uploaded by the user. An mpc image is created, B,
which is used to crate the thumbnails C, D, and E.