From f146cbc4b2b914e0663353b5bf751a4b26d2b441 Mon Sep 17 00:00:00 2001 From: Ghalleb Date: Wed, 20 Sep 2017 04:47:41 +0800 Subject: [PATCH] Save profile images to Amazon S3 (#1857) * Profile Image to S3 * Delete image from S3 Fix file deletion * S3 refactoring --- README.md | 9 ++ config/env/default.js | 9 ++ .../core/client/views/header.client.view.html | 2 +- .../change-profile-picture.client.view.html | 2 +- .../users/users.profile.server.controller.js | 90 +++++++++++++++---- package.json | 3 + 6 files changed, 95 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a38ef34491..92cedc08da 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,15 @@ $ docker run -p 27017:27017 -d --name db mongo $ docker run -p 3000:3000 --link db:db_1 mean ``` +### Amazon S3 configuration + +To save the profile images to S3, simply set those environment variables: +UPLOADS_STORAGE: s3 +S3_BUCKET: the name of the bucket where the images will be saved +S3_ACCESS_KEY_ID: Your S3 access key +S3_SECRET_ACCESS_KEY: Your S3 access key password + + ## Getting Started With MEAN.JS You have your application running, but there is a lot of stuff to understand. We recommend you go over the [Official Documentation](http://meanjs.org/docs.html). In the docs we'll try to explain both general concepts of MEAN components and give you some guidelines to help you improve your development process. We tried covering as many aspects as possible, and will keep it updated by your request. You can also help us develop and improve the documentation by checking out the *gh-pages* branch of this repository. diff --git a/config/env/default.js b/config/env/default.js index 35d1948bd2..6da548b5a1 100644 --- a/config/env/default.js +++ b/config/env/default.js @@ -45,7 +45,16 @@ module.exports = { illegalUsernames: ['meanjs', 'administrator', 'password', 'admin', 'user', 'unknown', 'anonymous', 'null', 'undefined', 'api' ], + aws: { + s3: { + accessKeyId: process.env.S3_ACCESS_KEY_ID, + secretAccessKey: process.env.S3_SECRET_ACCESS_KEY, + bucket: process.env.S3_BUCKET + } + }, uploads: { + // Storage can be 'local' or 's3' + storage: process.env.UPLOADS_STORAGE || 'local', profile: { image: { dest: './modules/users/client/img/profile/uploads/', diff --git a/modules/core/client/views/header.client.view.html b/modules/core/client/views/header.client.view.html index d35f961dc5..c09e9770a8 100644 --- a/modules/core/client/views/header.client.view.html +++ b/modules/core/client/views/header.client.view.html @@ -32,7 +32,7 @@