Download S3 directory as output stream

时间:2019-05-31 11:25:21

标签: java amazon-web-services amazon-s3

I want to write API which will download S3 Directory and return response media type as octet stream.

I have tried TransferManager with MultiFileDownload sample code as:

TransferManager transferManager = TransferManagerBuilder.standard().withS3Client(s3client)
                .withDisableParallelDownloads(false).withMinimumUploadPartSize(Long.valueOf(5 * MB))
                .withMultipartUploadThreshold(Long.valueOf(16 * MB)).withMultipartCopyPartSize(Long.valueOf(5 * MB))
                .withMultipartCopyThreshold(Long.valueOf(100 * MB)).withExecutorFactory(new ExecutorFactory() {

                    @Override
                    public ExecutorService newExecutor() {
                        return createExecutorService(20);
                    }
                }).build();

file = new File("SomePath");
MultipleFileDownload multipleFileDownload = transferManager.downloadDirectory("SomeBucketName","SomeObjectName", file);
multipleFileDownload.waitForCompletion();

How to return the S3 directory response as an octet stream to prevent connection timeout on the client side?

0 个答案:

没有答案