Код: Выделить всё
com.amazonaws.SdkClientException exception: The HTTP request cannot be executed: The peer resets the connection.
Без конфига
Код: Выделить всё
request.getRequestClientOptions().setReadLimit(custom buffer size);
Код: Выделить всё
The request to the service failed for a reason that can be repeated, but the reset of the request input stream failed. See exception.getExtraInfo or the debug log for information about the initial failure that caused this retry.; If the request includes an input stream, the maximum size of the stream buffer can be configured using request.getRequestClientOptions().setReadLimit(int)
Раньше ловил ошибку, вместо https был указан адрес сервера с бакетом http, файлы загружались размером пару кб, 100 кб - ошибка http
Код метода:
Код: Выделить всё
public ResponseEntity uploadFile(String catalogId, MultipartFile file) {
if (file == null || file.isEmpty()) {
return ResponseEntity.status(400).body(new ErrorResponse("Файл не передан"));
}
if (file.getSize() > maxFileSize * 1024 * 1024) {
return ResponseEntity.status(PAYLOAD_TOO_LARGE).contentType(MediaType.APPLICATION_JSON).body(new ErrorResponse("Размер файла не должен превышать: " + maxFileSize + " Мб"));
}
log.info("Начинаем загрузку файла: {}", file.getOriginalFilename());
String filePath = PathGenerator.generateFileUri(catalogId);
try {
// if (checkExists(filePath)) {
// log.info("Такой файл уже есть, удаляем для создания нового");
// deleteFile(filePath);
// }
ObjectMetadata meta = new ObjectMetadata();
meta.setContentType(file.getContentType());
meta.setContentLength(file.getSize());
meta.addUserMetadata("originalFileName", URLEncoder.encode(requireNonNull(file.getOriginalFilename()), StandardCharsets.UTF_8));
PutObjectRequest request = new PutObjectRequest(bucketName, filePath, file.getInputStream(), meta);
if (isCustomBufferSize) {
request.getRequestClientOptions().setReadLimit(customBufferSize);
}
awsConfig.getAwsClient().putObject(request);
log.info("Файл успешно загружен!");
HashMap response = new HashMap();
response.put("fileUuid", filePath);
return ResponseEntity.ok().body(response);
} catch (Exception e) {
log.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(MediaType.APPLICATION_JSON).body(new ErrorResponse("Ошибка записи: " + e.getMessage()));
}
}
Код: Выделить всё
public AmazonS3 getAwsClient() {
String str = s3endpoint;
String[] arr = str.split("://");
String endpoint;
Protocol protocol;
if (arr.length == 1) {
protocol = Protocol.HTTP;
endpoint = str;
} else {
protocol = (arr[0].equalsIgnoreCase(Protocol.HTTPS.name())) ? Protocol.HTTPS : Protocol.HTTP;
endpoint = arr[1];
}
ClientConfiguration clientConfig = new ClientConfiguration();
clientConfig.setProtocol(protocol);
clientConfig.setSocketTimeout(60000);
if (endpoint.contains("10.241.34.61")) {
return AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
.withClientConfiguration(clientConfig)
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, Region.EU_Ireland.getFirstRegionId()))
.withPathStyleAccessEnabled(true)
.build();
} else {
return AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
.withClientConfiguration(clientConfig)
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, Region.US_Standard.getFirstRegionId()))
.withPathStyleAccessEnabled(true)
.build();
}
}
Подробнее здесь: https://stackoverflow.com/questions/789 ... reset-by-p