Last active
March 20, 2020 08:32
-
-
Save faizakram/87752d46a701da577bc97c579da7ad05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.st.fileUplaod; | |
import java.io.File; | |
import com.amazonaws.auth.AWSStaticCredentialsProvider; | |
import com.amazonaws.auth.BasicAWSCredentials; | |
import com.amazonaws.regions.Regions; | |
import com.amazonaws.services.s3.AmazonS3; | |
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | |
/*Add this Jar File | |
* <dependency> | |
<groupId>com.amazonaws</groupId> | |
<artifactId>aws-java-sdk</artifactId> | |
<version>1.11.163</version> | |
</dependency>*/ | |
public class S3Main { | |
private static final File folder = new File("E:/Websites/File"); | |
private static final String accesskey = "<<accessKey>>"; | |
private static final String secretkey = "<<SecretKey>>"; | |
private final AmazonS3 amazonS3; | |
S3Main(String accesskey, String secretkey) { | |
amazonS3 = AmazonS3ClientBuilder.standard() | |
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accesskey, secretkey))) | |
.withRegion(Regions.AP_SOUTH_1).build(); | |
} | |
/** | |
* | |
* @param folder | |
* @return | |
*/ | |
public void upload(File folder) { | |
for (File file : folder.listFiles()) { | |
amazonS3.putObject("my-bucket-gagan", file.getName(), file); | |
System.out.println(file.getName()+ " -- Uploaded"); | |
} | |
} | |
public static void main(String[] args) { | |
S3Main s3Main = new S3Main(accesskey, secretkey); | |
s3Main.upload(folder); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment