Thanks bro. It was much helpful :) <3.
Note for the future readers:
1) AmazonS3Client is now deprecated. So, the above highlighted line should be changed to this.amazonS3 = AmazonS3ClientBuilder.standard().withRegion(s3Region).withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
where s3Region is your region name as a string.
2) The line where the fileURL is formed should be moved below the "uploadFileToBucket" method call, otherwise it will return the fileURL as if the file has been uploaded, even in the cases where the file hasn't actually been uploaded due to an error occured in "uploadFileToBucket".