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.

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

  1. 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
  2. Email suppliers work with the point of offering quick messaging serving, and file stockpiling isn't their essential undertaking. transfer large files

    ReplyDelete
  3. Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome! file storage

    ReplyDelete
  4. Your work is very good and I appreciate you and hopping for some more informative posts. Thank you for sharing great information to us. Scum buckets

    ReplyDelete
  5. Please add code for file upload using folder passing key. Above code references file which I didn't see the object creation.

    ReplyDelete