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
已提问 2 年前143 查看次数
没有答案

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则