How to upload files into the AWS S3 bucket using java

                       HOW TO UPLOAD FILES INTO AWS S3 BUCKET USING JAVA

  • First, create the object of AWSCredentials and pass the aws_access_key_id and aws_secret_access_key as parameters.
  • Next, create the s3client object for connecting to the aws s3 bucket.
  • For creating a connection we can pass the AWSCredentials object as a parameter.
  • Using the createBucket method so we can create the bucket.
  • Using the putObject method to upload the file into the aws s3 bucket.
File upload process in java

import com.amazonaws.ClientConfiguration; import java.io.File; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.PutObjectRequest; /** * * @author Janardhan Randhi * Date : Feb 4 2019 * Description : This class upload the file into AWS S3 storage blob. * */ public class AWSFileUpload { //private static final String SUFFIX = "/"; public static void main(String args[]) { AWSCredentials credentials = new BasicAWSCredentials( "*********Key", "**********pwd"); // create a client connection based on credentials AmazonS3 s3client = new AmazonS3Client(credentials,cc); // create bucket - name must be unique for all S3 users also small letter required String bucketName = "janardhan"; s3client.createBucket(bucketName); // create folder into bucket //String folderName = ""; here i am not taking any key(folder),if you want to create you can pass the key in put object method. long startTime = System.currentTimeMillis(); String fileName = file.getName();; s3client.putObject(new PutObjectRequest(bucketName, fileName, file)); System.out.println("file uploaded sucessfully to " + bucketName); long endTime = System.currentTimeMillis(); new File( file.getName()).delete(); //Delete the file from local system folder. System.out.println("Time taken to upload a single file : " + (endTime - startTime) + " milliseconds"); } }

SUBSCRIBE TO OUR NEWSLETTER

I’m the Founder of quickdevops.com. I am a Professional Blogger, Application developer, YouTuber. I’ve been blogging since 2015.I spend a lot of time learning new techniques and actively help other people learn web development through a variety of help groups and writing web development tutorials for my website and blog about advancements in web design and development.Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie or planning a trip to someplace I've never been before.

3 Responses to "How to upload files into the AWS S3 bucket using java"

  1. IEEE Cloud computing DOamin is a general term for anything that involves delivering hosted services over the Internet. IEEE Projects on Cloud Computing The cloud is a metaphor for a global network of remote servers which operates as a single ecosystem, commonly associated with the Internet. IEEE FInal Year Project Domains Final Year Projects for CSE cloud computing is the delivery of computing services—including servers, storage, databases, networking, software, analytics, and intelligence


    JavaScript Training in Chennai


    JavaScript Training in Chennai

    ReplyDelete
  2. As we probably am aware, mp4 is a configuration that playable on macintosh, so on the off chance that you need to watch swf document on macintosh you can change over swf to mp4 macintosh.www.anyconv.com

    ReplyDelete