Code Monkey home page Code Monkey logo

aws-s3-image-upload-spring-boot-app's Introduction

AWS-S3-image-upload-spring-boot-app

A java spring-boot photo uploading app which saves all the photos uploaded from a simple UI to an AWS S3 Bucket.

Below AWS services are used to achieve the functionality.

  1. AWS EC2
  2. AWS S3
  3. AWS IAM
  4. AWS CodeCommit
  5. AWS SDK for Java

Explanation

The photo uploading system is hosted in a t2.micro AWS EC2 instance. And this application runs on port 8080.

When the user uploads the images through the application UI, all the images are saved in an AWS S3 bucket named "AshenTestawsbucket"

AWS IAM service is used in order to enable the web application to access AWS services via an IAM programmatic user. That user is set to a ‘Group’ named ‘S3_App_User’ which has 'AmazonS3FullAccess'

AWS SDK for Java is used in order to upload the images to AWS S3. Below is the maven dependency for the aws java client.

<dependency>
		   <groupId>com.amazonaws</groupId>
		   <artifactId>aws-java-sdk</artifactId>
		   <version>1.11.106</version>
</dependency>

To upload a file, AmazonS3.putObject() method is used.

After a file has been uploaded by the user through the UI, the file will be received to /home/uploadFile path as a multipart POST request

 @PostMapping("/uploadFile")
    public String uploadFile(@RequestPart(value = "file") MultipartFile multipartFile) {

Thereafter, the 'org.springframework.web.multipart.MultipartFile' is converted to 'java.io.file' using the below code since the PutObjectRequest(String bucketName, String key, File file) use java.io.File.

 File convFile = new File(file.getOriginalFilename());
 FileOutputStream fos = new FileOutputStream(convFile);
 fos.write(file.getBytes());
 fos.close();

Next, we use the putObject() method which includes s3 bucket name (taken from application.properties file), file name and converted file as params to upload the file to the specified amazon s3 bucket.

s3client.putObject(new PutObjectRequest(bucketName, fileName, file));

Testing Steps and Commands used

  1. added ssh port 22 connection of the ip address of my computer to the security group of the ec2 instance.

  2. Copied the aws-image upload app's jar file to the ec2 instances using below commands

    sudo scp -i awsPrivateKey.pem target/aws-assignment-s3-0.0.1-SNAPSHOT.jar [email protected]:/var/tmp
    sudo ssh -i awsPrivateKey.pem [email protected]
    Copied tmp folder to home folder
    cp /var/tmp/aws-assignment-s3-0.0.1-SNAPSHOT.jar .
  1. Run the java app using below command

java -jar aws-assignment-s3-0.0.1-SNAPSHOT.jar

  1. when login in next time, Don't forget to change the ip address of your computer in the security group section of ec2 instance port 22.

aws-s3-image-upload-spring-boot-app's People

Contributors

ashenjy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.