S3 Upload CSV with GZIP Compression using InputStream

0

Hi,

I am currently working on a usecase where, I am creating csv input stream programmatically using JAVA Code and than I have to compress it to gzip and than upload it to s3 bucket. Which will further use by AWS Neptune for bulk data ingestion.

I am able to create inputstream and upload a CSV file on s3 bucket without gzip, but didn't find any luck to add one more gzip compression step between uploading and inputstream creation.

Please find the current snippet of the code which is working fine -

/**
     * This method will upload the input stream to s3 with csv format.
     *
     * @param fileName    file name
     * @param inputStream input stream
     */
    public void uploadFile(String fileName, InputStream inputStream) {
        try (S3Client s3Client = S3Client.builder().region(Region.AWS_GLOBAL).build()) {
            PutObjectRequest requestObject = PutObjectRequest
                    .builder()
                    .bucket(bucketName)
                    .key(java.time.LocalDate.now() + "/" + fileName)
                    .build();
            s3Client.putObject(requestObject, RequestBody.fromBytes(inputStream.readAllBytes()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
mann
asked 2 years ago143 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions