Я пытаюсь загрузить gzip-файл в корзину S3. Но когда длина файла не установлена, небольшие файлы загружаются нормально, а огромный файл размером более 2 ГБ не загружается.
Когда размер файла установлен, все файлы, включая маленькие, загружаются успешно, но содержимое повреждено.
Может кто-нибудь предложить решение для этого.
` private void getAndProcessFilesGenReports(String parUrl, String custCode, String queryDate) {
try (CloseableHttpClient httpclient = HttpClientBuilder.create().setDefaultCredentialsProvider(getCredentialsProvider()).build();) {
CloseableHttpResponse response;
HttpGet httpget = new HttpGet(BASE_URI.concat(parUrl));
response = httpclient.execute(httpget);
httpget.setConfig(config);
log.info("getAndProcessFilesGenReports CloseableHttpResponse status code-->{}, reason phrase--->{}",
response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
if (response.getStatusLine().getStatusCode() != 200) {
log.error("getAndProcessFilesGenReports partUrl could not get response for custCode---> {}", custCode);
}
if (response.getStatusLine().getStatusCode() == 200) {
try (InputStream input = response.getEntity().getContent()) {
String bucketName = bucketForDetailedBilling(GEN_REPORT_TYPE, custCode, queryDate);
uploadGzipFileToS3(input,input.available(), bucketName);
}
}
} catch (Exception e) {
log.error("error in getAndProcessFilesGenReports()--->", e);
}
}
private void uploadGzipFileToS3(InputStream gzis,long size, String bucketName) throws Exception {
log.info("uploadGzipFileToS3 size{} --- bucketName {}--->", size, bucketName);
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setConnectionMaxIdleMillis(600000);
clientConfiguration.setConnectionTimeout(600000);
clientConfiguration.setClientExecutionTimeout(600000);
clientConfiguration.setUseGzip(true);
clientConfiguration.setConnectionTTL(1000 * 60 * 60);
AmazonS3Client amazonS3Client = new AmazonS3Client(clientConfiguration);
TransferManager transferManager = new TransferManager(amazonS3Client);
try {
log.info("uploadGzipFileToS3 s3Client up--->");
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(size);
log.info("uploadGzipFileToS3 objectMetadata setting ContentLength to --->{}", size);
transferManager.getConfiguration().setMultipartUploadThreshold(5 * 1024L);
log.info("uploadGzipFileToS3 setting MultipartUploadThreshold to--->{}", 5);
PutObjectRequest request = new PutObjectRequest(bucketName, DBR_NAME + DBR_EXT, gzis,objectMetadata);
request.getRequestClientOptions().setReadLimit(1024 * 5 + 1);
request.setSdkClientExecutionTimeout(10000 * 60 * 60);
log.info("uploadGzipFileToS3 setting setReadLimit to--->1 byte more than 5mb");
Upload upload = transferManager.upload(request);
log.info("uploadGzipFileToS3 transferManager upload invoked, waiting for completion--->");
upload.waitForCompletion();
log.info("TelenorHelper uploadGzipFileToS3 transferManager upload invoked and completed--->");
} catch (InterruptedException e) {
log.error("InterruptedException in uploadGzipFileToS3 --->", e);
} catch (AmazonServiceException e) {
log.error("AmazonServiceException in uploadGzipFileToS3 --->", e);
} catch (SdkClientException e) {
log.error("SdkClientException in uploadGzipFileToS3 --->", e);
} finally {
try {
gzis.close();
} catch (IOException e) { log.
error("uploadGzipFileToS3 error occured while closing gzip input stream {}--->", e);
}
transferManager.shutdownNow();
}
}