我正在测试使用"aws-java-sdk-s3"将小对象上传到S3的不同方法。 由于是小对象,所以我使用默认的API(用于大型和巨大对象的传输API...)。
Uploading a File as a source, perfect !
File file = .... s3Client.putObject(new PutObjectRequest(bucket, key, file));
Uploading ByteArrayInputStream, perfect !
InputStream stream = new ByteArrayInputStream("How are you?".getBytes())) s3Client.putObject(new PutObjectRequest(bucket, key, stream ));
Updloading a Resource As Stream , problems .!
InputStream stream = this.getClass().getResourceAsStream("myFile.data"); s3Client.putObject(new PutObjectRequest(bucket, key, stream ));
异常处理:
com.amazonaws.ResetException: The request to the service failed with a retryable reason, but resetting the request input stream has failed.
See exception.getExtraInfo or debug-level logging for the original failure that caused this retry.;
If the request involves an input stream, the maximum stream buffer size can be configured via request.getRequestClientOptions().setReadLimit(int)
Caused by: java.io.IOException: Resetting to invalid mark
at java.io.BufferedInputStream.reset(BufferedInputStream.java:448)
at com.amazonaws.internal.SdkFilterInputStream.reset(SdkFilterInputStream.java:112)
at com.amazonaws.internal.SdkFilterInputStream.reset(SdkFilterInputStream.java:112)
at com.amazonaws.util.LengthCheckInputStream.reset(LengthCheckInputStream.java:126)
at com.amazonaws.internal.SdkFilterInputStream.reset(SdkFilterInputStream.java:112)
我可以使用Apache File Utils将类路径资源转换为文件对象,但它有点糟糕......
- 我是否必须根据流的类型来配置ReadLimit?
- 推荐使用什么值?
API版本:"aws-java-sdk-s3" rev="1.11.442"