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
posta 2 anni fa143 visualizzazioni
Nessuna risposta

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande