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.
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");
}
}
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
ReplyDeleteWonderful blog...! This information is very helpful for enhancing my knowledge and Thank you...!
ReplyDeleteOracle DBA Training in Chennai
best oracle dba training in chennai
Spark Training in Chennai
Oracle Training in Chennai
Graphic Design Courses in Chennai
Excel Training in Chennai
Unix Shell Scripting Training in Chennai
Placement Training in Chennai
Soft Skills Training in Chennai
JMeter Training in Chennai
Tableau Training in Chennai
Email suppliers work with the point of offering quick messaging serving, and file stockpiling isn't their essential undertaking. transfer large files
ReplyDeleteAwesome 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
ReplyDeleteYour 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
ReplyDeleteThanks for providing recent updates regarding the concern, I look forward to read more. Scum buckets
ReplyDeletePlease add code for file upload using folder passing key. Above code references file which I didn't see the object creation.
ReplyDelete