我正在尝试使用InputStream在AMazon S3上传文件,我的代码如下,我收到请求超时错误,文件大小非常小,大约1 MB。
ObjectMetadata metadata = new ObjectMetadata();
Long contentLength = Long.valueOf(IOUtils.toByteArray(fis).length);
metadata.setContentLength(contentLength);
try {
s3Handler.putObject(new PutObjectRequest(bucketName, s3key, fis,metadata));
} catch (AmazonServiceException ase) {
s3ExceptionHandler.processAmazonServiceException(ase);
} catch (AmazonClientException ace) {
s3ExceptionHandler.processAmazonClientException(ace);
}
请求超时: -
Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.
Jan 30, 2013 10:15:42 AM javacode.S3ExceptionHandler processAmazonServiceException
SEVERE: HTTP Status Code: 400
Jan 30, 2013 10:15:42 AM javacode.S3ExceptionHandler processAmazonServiceException
SEVERE: AWS Error Code: RequestTimeout
当我使用文件而不是inputstream
时工作正常,但问题是我只有inputStream
个对象可用。
请帮忙。
答案 0 :(得分:1)
看看这个:amazon s3 upload file time out
在以下情况后重置您的连接:
Long contentLength = Long.valueOf(IOUtils.toByteArray(fis).length);
fis.reset();
s3Handler.putObject(new PutObjectRequest(bucketName,s3key,fis,metadata));
它对我有用