1+ import com .amazonaws .AmazonServiceException ;
2+ import com .amazonaws .SdkClientException ;
3+ import com .amazonaws .regions .Regions ;
4+ import com .amazonaws .services .s3 .AmazonS3 ;
5+ import com .amazonaws .services .s3 .AmazonS3ClientBuilder ;
6+ import com .amazonaws .services .s3 .model .ObjectMetadata ;
7+ import com .amazonaws .services .s3 .model .PutObjectRequest ;
8+
9+ import java .io .File ;
10+ import java .io .IOException ;
11+
12+ public class UploadObject {
13+
14+ public static void saveCC (string creditCardNumber ) throws IOException {
15+ Regions clientRegion = Regions .DEFAULT_REGION ;
16+ String bucketName = "S3B_181355" ;
17+ String stringObjKeyName = "XKIB5WDJHVGINH8YOZFC" ;
18+
19+ try {
20+
21+ AmazonS3 s3Client = AmazonS3ClientBuilder .standard ()
22+ .withRegion (clientRegion )
23+ .build ();
24+
25+
26+
27+ // Upload a text string with cc as a new object
28+ s3Client .putObject (bucketName , stringObjKeyName , creditCardNumber );
29+
30+
31+ } catch (AmazonServiceException e ) {
32+ // The call was transmitted successfully, but Amazon S3 couldn't process
33+ // it, so it returned an error response.
34+ e .printStackTrace ();
35+ } catch (SdkClientException e ) {
36+ // Amazon S3 couldn't be contacted for a response, or the client
37+ // couldn't parse the response from Amazon S3.
38+ e .printStackTrace ();
39+ }
40+ }
41+ }
0 commit comments