Skip to content

Potential problem in uploading data using AsyncRequestBody.fromPublisher() #2493

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

Closed
masokan opened this issue May 23, 2021 · 6 comments
Closed
Labels
guidance Question that needs advice or information.

Comments

@masokan
Copy link

masokan commented May 23, 2021

Describe the bug

Exception thrown when normal completion is expected

Expected Behavior

Upload should be successful without any exception

Current Behavior

An exception is thrown

Please see the github repository https://github.com/masokan/test-s3-upload for an example and error log

Steps to Reproduce

Please see https://github.com/masokan/test-s3-upload#readme for more details

Possible Solution

Context

I am trying to upload a stream of data for which the size is unknown

Your Environment

  • AWS Java SDK version used: 2.16.68
  • JDK version used: Open JDK 1.8
  • Operating System and version: Linux (Ubuntu 20.04)
@masokan masokan added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 23, 2021
@debora-ito
Copy link
Member

Hi @masokan,

software.amazon.awssdk.services.s3.model.S3Exception: You must provide the Content-Length HTTP header is a message returned by S3 saying that content-length is required for the operation you're calling. You must provide the content-length to the putObject request.

@debora-ito debora-ito added closing-soon This issue will close in 4 days unless further comments are made. guidance Question that needs advice or information. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 25, 2021
@masokan
Copy link
Author

masokan commented May 25, 2021

Hi @debora-ito, my application generates content dynamically for which the length is not known beforehand. My understanding is that AsyncRequestBody.fromPublisher() API is meant to send such content. The content is published as a series of ByteBuffer objects that the API accepts and uploads. The content length is defined to be Optional.empty() in AsyncRequestBody.java (which is in aws-java-sdk-v2.)

If you think I am using the wrong API, please let me know any other asynchronous API that I can use to upload content for which the length is unknown. Thanks.

@github-actions github-actions bot removed the closing-soon This issue will close in 4 days unless further comments are made. label May 26, 2021
@masokan
Copy link
Author

masokan commented May 26, 2021

Please take a look at the source code: https://github.com/masokan/test-s3-upload/blob/main/src/main/java/com/mycompany/test/StreamUpload.java
It uses AWS SDK API that does not require any content size to be specified but while running it an exception is thrown indicating content length is missing in HTTP header.

@masokan
Copy link
Author

masokan commented May 31, 2021

Hi @debora-ito I think the feature I am looking for (uploading streamed content for which length is unknown) is not supported by AWS Java SDK v2. A quick search landed me on aws/aws-sdk-java#474 where several users were looking for the same missing feature. Also, the strange thing is that the exception is thrown after all data to be uploaded is published by the Publisher. It is not thrown in the call to S3AsyncClient.putObject() itself.
I have worked with other cloud vendor libraries and they all provide streaming APIs which do not require content length to be specified upfront.
This issue is a blocker for a current project that I am working on. Please change the status as a 'feature request.' Thanks.

@debora-ito
Copy link
Member

@masokan we are tracking this as one the many features of the V2 version of TransferManager, aws/aws-sdk-java#474 was brought out in the comments - #37 (comment).

I'll go ahead and close this, you can monitor the progress on the TransferManager v2 tracking issue - #37. Feel free to reach out with other questions.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

2 participants