我正在嘗試使用Amazon S3 JAVA sdk獲取文件大小(內容長度)。從S3存儲桶獲取文件大小
public Long getObjectSize(AmazonS3Client amazonS3Client, String bucket, String key)
throws IOException {
Long size = null;
S3Object object = null;
try {
object = amazonS3Client.getObject(bucket, key);
size = object.getObjectMetadata().getContentLength();
} finally {
if (object != null) {
//object.close();
1. This results in 50 calls (connection pool size) post that I start getting connection pool errors.
2. If this line is uncommented it takes hell lot of time to make calls.
}
}
return size;
}
我跟着this和this。但不知道我在這裏做錯了什麼。 對此有何幫助?
請閱讀此:http://stackoverflow.com/help/how-to-ask然後更新您的問題,以確切指出您的問題是什麼。你有錯誤嗎?你得到不正確的文件大小?你的代碼中有一些關於調用'object.close()'的註釋需要很長時間,但是這似乎與獲取對象文件大小的問題完全不同。 –