Awesome Open Source
Awesome Open Source

Node.js S3 Image Uploader

Codacy Badge npm version

A simple Node.js wrapper of the AWS SDK for uploading images to S3. This was originally created to assist with uploading images from serverless applications on AWS Lambda to s3.

Installation

Install the package with NPM and add it to your dependencies.

$ npm install node-s3-image-uploader --save

Basic Usage

Include the module.

const Uploader = require('node-s3-image-uploader');

Instantiate the uploader

var uploader = new Uploader(bucketName, options);

The bucketName parameter is a required string containing your DNS-compliant S3 bucket name. The Uploader can also take an optional options object as a param. For example:

var options = {
    filePath: 'images/'
}

var uploader = new Uploader('bucketname.com', options);

You can then call the upload(image, callback) function:

var image = // Must be in base64 format;
var uploader.upload(image, callback);

API

Uploader(string bucketName, {} options)
  • string bucketName - DNS-compliant S3 bucket name (required)
  • object options - configurable upload options (optional)
    • string filePath - folder path to place the image (e.g. 'images/'). This defaults to the root directory of the bucket. There must not be a preceding /. The trailing / is required.

Note

For this package to work correctly, it is assumed that your environment (e.g. AWS Lambda function) is configured with the correct roles to access s3 and perform a putObject action.

License

This package is released under the MIT license. It is simple and easy to understand and places almost no restrictions on what you can do with the code. More Information


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,554,932
Nodejs (54,754
Node (13,116
Serverless (4,788
Aws Lambda (3,035
Aws S3 (1,181
Related Projects