JavaFX connecting AWS S3 bucket simple sample
I just joined this workshop Java workshop for only women
and AWS workshop for only women last week.
It was very fun to take part in this kind of events.
At first we introduced ourselves and mentioned own today's task.
Then having fun time with teaching each other.
At last we announced today's result of each person.
My goal is implementing JavaFX sample, which connecting AWS S3. Then to show S3's buckets in JavaFX.
- AWS console
Showing the S3 bucket on JavaFX.
- FXMLDocumentController.java
Connecting to AWS
AmazonS3 s3 = new AmazonS3Client();
Region usWest2 = Region.getRegion(Regions.US_WEST_2);
s3.setRegion(usWest2);
Getting S3 bucket, and creating Tab.
s3.listBuckets().forEach(bucket -> { // creating tab for each bucket Tab tab = new Tab(); String bucketNm = bucket.getName(); tab.setText(bucketNm); tabPane.getTabs().add(tab); VBox vbox = new VBox(10); vbox.setPadding(new Insets(10)); vbox.setStyle("-fx-background-color: #ffc9ae"); // Owner HBox hbox1 = new HBox(10); Label ownerLabel = new Label("Owner:"); String owner = bucket.getOwner().getDisplayName(); Text ownerText = new Text(owner); hbox1.getChildren().addAll(ownerLabel, ownerText); // Create Date HBox hbox2 = new HBox(10); Label dateLabel = new Label("Create Date:"); String createDate = bucket.getCreationDate().toString(); Text dateText = new Text(createDate); hbox2.getChildren().addAll(dateLabel, dateText); tab.setContent(vbox); tab.setStyle("-fx-background-color: #ffc9ae;"); // ListView for file path ObservableList<String> items = FXCollections.observableArrayList("file path"); ListView view = new ListView(items); ObjectListing objList = s3.listObjects(new ListObjectsRequest() .withBucketName(bucketNm) .withPrefix("")) ; objList.getObjectSummaries().forEach(obj -> { String filePath = obj.getKey(); items.add(filePath); }); vbox.getChildren().addAll(hbox1, hbox2, view); });
Whole code is here GitHub - tomoTaka01/JavaFXAWSS3Sample: AWS S3 simple sample by JavaFX
- Finally
I would like to express my gratitude to staff as well as Osakan Space.
Osakan Space
just keep coding... ;-)