Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
880 B
4
Indexable
Never
@GetMapping("/json")
    @ResponseBody
    public String getJsonFromS3() {
        AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                                .withRegion("your-region")
                                .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)))
                                .build();

        S3Object s3Object = s3Client.getObject(BUCKET_NAME, OBJECT_KEY);

        StringBuilder jsonContent = new StringBuilder();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(s3Object.getObjectContent()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                jsonContent.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return jsonContent.toString();
    }
Leave a Comment