|
1 |
| -# Asset Uploader |
| 1 | +# S3 Asset Uploader with Sharp optimization |
| 2 | + |
| 3 | +Simple S3 image asset uploader with Sharp optimization. It is very simple and barebones, but it does the job. |
| 4 | +- In future I plan to extend this to also support videos and documents. |
| 5 | + |
| 6 | +Run it on localhost to optimize and upload images to S3. Retrieved links of uploaded images point to Cloudfront and can be used in production. |
| 7 | + |
| 8 | +## Preview |
| 9 | +<img src="assets/preview.png" alt="App Preview" width="800"/> |
| 10 | + |
| 11 | +## Pre-requisites |
| 12 | + |
| 13 | +1) Setup S3 bucket with Cloudfront distribution in front of it. This app returns Cloudfront links after you upload the image. [This video](https://www.youtube.com/watch?v=kbI7kRWAU-w) can help you with that. |
| 14 | +2) Create IAM user with following policy (replace "your-bucket-name" with your actual bucket name) |
| 15 | +``` |
| 16 | +{ |
| 17 | + "Version": "2012-10-17", |
| 18 | + "Statement": [ |
| 19 | + { |
| 20 | + "Effect": "Allow", |
| 21 | + "Action": [ |
| 22 | + "s3:GetObject", |
| 23 | + "s3:PutObject", |
| 24 | + "s3:ListBucket" |
| 25 | + ], |
| 26 | + "Resource": [ |
| 27 | + "arn:aws:s3:::your-bucket-name", |
| 28 | + "arn:aws:s3:::your-bucket-name/*" |
| 29 | + ] |
| 30 | + } |
| 31 | + ] |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +## How to setup |
| 36 | +1) Download or git clone this repo |
| 37 | +2) Create .env file based on .env.example and place it in the root of the project |
| 38 | + - The region needs to be us-east-1 for Cloudfront to work (it is global, but according to AWS it has to be configured in us-east-1) |
| 39 | +3) Run `npm run install` or `yarn install` or `pnpm install` (I use pnpm, but other package managers should work too) |
| 40 | +4) Run `npm run dev` or `yarn dev` or `pnpm dev` to start the server |
| 41 | +5) Open your browser and go to `http://localhost:3010` |
| 42 | + |
| 43 | +## How to use |
| 44 | +1) **Run it on localhost** <small>(npm run dev)</small> |
| 45 | +- <small>#1 Optimization Form</small> |
| 46 | +2) **Select image from filesystem** |
| 47 | +3) **Fill in quality and size** <small>(at least height or width has to be filled in, Sharp will calculate the other parameter automatically)</small> |
| 48 | +4) **Click optimize** <small>-> optimized image will be previewed in the Upload Form</small> |
| 49 | +- <small>#2 Upload Form</small> |
| 50 | +5) **Fill in the new image name** (technically S3 namespace) <small>-> it will be automatically prefixed with assets/images/</small> |
| 51 | +6) **Click upload** <small>-> image will be uploaded to S3 bucket and Cloudfront link will be returned</small> |
0 commit comments