An Express.js "module" providing the ability to upload multiple images to S3 using a simple, extensible interface.
- A Heroku account
- An Amazon AWS account
- Your Amazon AWS Access Key and Secret Key
- An Amazon S3 bucket, for storing the images
- Node.js and NPM properly installed
See the amazon-s3-multi-uploader-example repository for a working implementation of the "module", and how you might approach integrating it into your own express.js application.
Add the following config variables to your Heroku application:
AWS_ACCESS_KEY_ID
- Your Amazon AWS Access KeyAWS_SECRETACCESS_KEY
- Your Amazon AWS Secret KeyS3_BUCKET_NAME
- The Amazon S3 bucket to store the uploaded filesMAX_UPLOAD_SIZE
- The maximum file size, in bytes
heroku config:set AWS_ACCESS_KEY_ID=secret \
AWS_SECRET_ACCESS_KEY=secret \
S3_BUCKET_NAME=foo-bar-baz \
MAX_UPLOAD_SIZE=5242880
Add this CORS policy to your S3 bucket, making sure to replace http://YOUR_WEBSITE
with the url where the uploader will be hosted.
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://YOUR_WEBSITE/</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
</CORSRule>
</CORSConfiguration>
In your code, you can hook into the post-upload callback by defining your own angular module in your project's JavaScript:
/* Services */
angular.module('uploaderApp.services', []).
factory('notify', ['$window', function($window) {
return function($scope, file) {
console.log("Upload completed", file);
}
}
]);