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
preguntada hace 2 años143 visualizaciones
No hay respuestas

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas