Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add S3Template upload ability of InputStream and content length #922

Open
apetrelli opened this issue Oct 24, 2023 · 4 comments
Labels
component: s3 S3 integration related issue

Comments

@apetrelli
Copy link

Type: Feature

I notice that, for a simple upload of an InputStream, an entire S3Resource has to be created along with the S3OutputStream. This results in putting all the data or in memory or to disk

It would be nice to have, in S3Operations and S3Template, an upload method that has the following signature:

S3Resource upload(String bucketName, String key, InputStream inputStream, long contentLength)

This should call S3Client.putObject with RequestBody.fromInputStream, that uses the input stream and the content length so not to read the file twice, or dump in memory or on file.

@maciejwalkowiak
Copy link
Contributor

The S3OutputStream implementations we provide don't store complete file in memory or on disk, see InMemoryBufferingS3OutputStream.

I understand the reasoning but we would have to make it very clear that this particular method does not use the S3OutputStream but goes directly to SDK.

@maciejwalkowiak maciejwalkowiak added the component: s3 S3 integration related issue label Oct 24, 2023
@apetrelli
Copy link
Author

@maciejwalkowiak another name is perfect for me as long as it works :-)

@apetrelli
Copy link
Author

Thinking about it, in fact what I wanted is something that uploads the InputStream without hitting the filesystem or putting everything in memory when the file is huge, so I guess that InMemoryBufferingS3OutputStream is perfect.
I leave this issue open though, because it might be interesting for someone else.

@zhemaituk
Copy link
Contributor

A decent implementation available in this lib: InMemoryBufferingS3OutputStream.
In a Spring app usage is quite clean, just inject S3OutputStreamProvider:

try (S3OutputStream s3Stream = inMemoryBufferingS3StreamProvider.create(bucket, key
                            ObjectMetadata.builder()
                                    .contentType("text/csv")
                                    .build())) {
   ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: s3 S3 integration related issue
Projects
None yet
Development

No branches or pull requests

3 participants