Uploading an image to Amazon S3
Uploading images to your server-side filesystem is actually not a great idea. If you are deploying from your repo, you don't want to mix in user-generated media with your code. A much better and more scalable approach is to put your photos and other media in a completely separate static location, such as Amazon S3, where you can access them without letting them interfere with your core application.
In this recipe, we will upload images to Amazon S3 and display them after they are uploaded.
Getting ready…
For this recipe, we will use the Amazon SDK for Node. It can be installed by running npm install aws-sdk –save
in your terminal. We will also use lodash (npm install lodash --save
) and the q
promise library (npm install q --save
).
How to do it…
To upload an image to Amazon S3, follow these steps:
First, we will create an
aws.service.js
file. This file will be responsible for interfacing with the Amazon AWS SDK and writing and reading binary data from Amazon. We...