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
gefragt vor 2 Jahren143 Aufrufe
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen