[Bug]: <AWSS3SigV4JavaSamples.zip has upload bug>
Expected behavior
Hello, I found a bug in the package "AWSS3SigV4JavaSamples.zip". I downloaded this package from "https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-examples-using-sdks.html#sig-v4-examples-using-sdk-java". when i upload to s3 ,I use PutS3ObjectSample.java
Actual behavior
<Error><Code>XAmzContentSHA256Mismatch</Code><Message>The provided 'x-amz-content-sha256' header does not match what was computed.</Message><ClientComputedContentSHA256>2efb07c3c3e1b736f4e12f249f63976829ff012cd7ef40a70b6e3ee6344e1217</ClientComputedContentSHA256><S3ComputedContentSHA256>2dd6d43a7a0748921c3fffee5687a3f28b51ded41e00fbb98926919db9d3aca3</S3ComputedContentSHA256><RequestId>6FFBPMHDEJM59CRF</RequestId><HostId>MvcUeKbrglSYeu72DE825vxqyBPSOu85K8bn8NSCGe+Cp+tmyjSl5qzuvkSXOB/CI5J1ZLdy9fg=</HostId></Error>
Steps to reproduce
Specifically, in "HttpUtils.invokeHttpRequest", "wr.writeBytes(requestBody)" will cause the server to calculate hash256 incorrectly when the content contains Chinese characters.
Logs / stacktrace (if applicable)
It is recommended to change it to "wr.write(requestBody.getBytes(StandardCharsets.UTF_8))"
Which SDK were you using?
Java
Which OS were you using?
macOS
SDK version
No response
OS version
No response
This is not a code example issue. Looks like a S3 Doc issue. I will reassign.
这不是代码示例问题。看起来像是 S3 Doc 问题。我会重新分配。
I would like to add that this should be a bug, because the char in JAVA is 16 bits, and one char stores one Chinese character. Directly converting it using the writeBytes method will become 8 bits, which directly causes the loss of the upper 8 bits. This leads to garbled Chinese characters.