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

Using BufferedInputStream causes an upload error #2876

Open
JavaLionLi opened this issue Nov 13, 2022 · 9 comments
Open

Using BufferedInputStream causes an upload error #2876

JavaLionLi opened this issue Nov 13, 2022 · 9 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@JavaLionLi
Copy link

Describe the bug

Upload files to receive using MultipartFile
MultipartFile.getInputStream return BufferedInputStream
Using BufferedInputStream causes an upload error

Expected Behavior

use bytes upload success

Current Behavior

image
image

Reproduction Steps

image

image

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

1.12.341

JDK version used

1.8.0_202

Operating System and version

centos7.6

@JavaLionLi JavaLionLi added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 13, 2022
@debora-ito debora-ito self-assigned this Nov 15, 2022
@debora-ito
Copy link
Member

Hi @JavaLionLi can you share a repro code in text format, not screenshot?
We ask for repro code for two main reasons: to better understand what the application is trying to do, and to be able to simply copy+paste the code and run it in our side to reproduce the error.

@debora-ito debora-ito added response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 15, 2022
@JavaLionLi
Copy link
Author

Hi @JavaLionLi can you share a repro code in text format, not screenshot? We ask for repro code for two main reasons: to better understand what the application is trying to do, and to be able to simply copy+paste the code and run it in our side to reproduce the error.

Simply put, PutObjectRequest use BufferedInputStream error

@JavaLionLi
Copy link
Author

JavaLionLi commented Nov 16, 2022

Hi @JavaLionLi can you share a repro code in text format, not screenshot? We ask for repro code for two main reasons: to better understand what the application is trying to do, and to be able to simply copy+paste the code and run it in our side to reproduce the error.

        try {
            // The file must be larger than 200kb
            BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream("D:\test.txt"));
            PutObjectRequest putObjectRequest = new PutObjectRequest("test", path, inputStream, new ObjectMetadata());
            client.putObject(putObjectRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }

@github-actions github-actions bot removed the response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. label Nov 16, 2022
@debora-ito
Copy link
Member

Can you share a code sample of how the s3 client is being created?

@debora-ito debora-ito added the response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. label Nov 18, 2022
@JavaLionLi
Copy link
Author

Can you share a code sample of how the s3 client is being created?

        AwsClientBuilder.EndpointConfiguration endpointConfig =
            new AwsClientBuilder.EndpointConfiguration("http://127.0.0.1:9000", "");
        AWSCredentials credentials = new BasicAWSCredentials("admin", "123456");
        AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
        ClientConfiguration clientConfig = new ClientConfiguration();
        AmazonS3ClientBuilder build = AmazonS3Client.builder()
            .withEndpointConfiguration(endpointConfig)
            .withClientConfiguration(clientConfig)
            .withCredentials(credentialsProvider)
            .disableChunkedEncoding();
        this.client = build.build();

use minio

@github-actions github-actions bot removed the response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. label Nov 18, 2022
@debora-ito
Copy link
Member

I can't reproduce the issue. I used the s3 endpoint though, not minio. Maybe it's a minio issue, do you see the same error when using the s3 endpoint directly?

You mentioned Multipart in the description, but the repro code calls a regular non-multipart PutObject, can you share a repro code for Multipart Upload? And if possible, please enable the DEBUG logs and share here when the error occurs. For instructions on how to enable DEBUG logs check Request/Response Summary Logging here: https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-logging.html#sdk-net-logging-request-response

@debora-ito debora-ito added the response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. label Nov 22, 2022
@JavaLionLi
Copy link
Author

JavaLionLi commented Nov 22, 2022

I can't reproduce the issue. I used the s3 endpoint though, not minio. Maybe it's a minio issue, do you see the same error when using the s3 endpoint directly?

You mentioned Multipart in the description, but the repro code calls a regular non-multipart PutObject, can you share a repro code for Multipart Upload? And if possible, please enable the DEBUG logs and share here when the error occurs. For instructions on how to enable DEBUG logs check Request/Response Summary Logging here: https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-logging.html#sdk-net-logging-request-response

Nothing to do with minio, Using a BufferedInputStream file larger than 500kb will result in an error, The error was reported before it was uploaded
image
image
BufferedInputStream uses reset to report errors, which can be found on the network

@github-actions github-actions bot removed the response-requested Waiting on additional info or feedback. Will move to "closing-soon" in 5 days. label Nov 22, 2022
@JavaLionLi
Copy link
Author

No one to deal with it?

@debora-ito debora-ito added the p2 This is a standard priority issue label Mar 27, 2023
@hqbhoho
Copy link

hqbhoho commented Oct 15, 2023

I had the same problem in sdk 2.x , So I try use java reflection to get BufferedInputSteam filed in (FileInputStream) and put it . @JavaLionLi
code like:

InputStream inputStream = file.getInputStream();
Field in = FilterInputStream.class.getDeclaredField("in");
in.setAccessible(true);
InputStream inNew = (InputStream)in.get(inputStream);
PutObjectResponse putObjectResponse = s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(inNew, size));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

3 participants