🐛 Fixing a bug. #1534 amazonaws oss Unable to execute HTTP request: Timeout waiting for connection from pool
This commit is contained in:
1 parent
81af2b2dc8
commit
ec3bbd900e
3 files changed
+13
-6
No files matched your search
+5
@@ -77,4 +77,9 @@ public class OssProperties {
|
||||
*/
|
||||
private String bucketName = "payerp";
|
||||
|
||||
/**
|
||||
* 最大线程数,默认: 100
|
||||
*/
|
||||
private Integer maxConnections = 100;
|
||||
|
||||
}
|
||||
+5
-3
@@ -138,8 +138,8 @@ public class OssTemplate implements InitializingBean {
|
||||
* API Documentation</a>
|
||||
*/
|
||||
@SneakyThrows
|
||||
public InputStream getObject(String bucketName, String objectName) {
|
||||
return amazonS3.getObject(bucketName, objectName).getObjectContent();
|
||||
public S3Object getObject(String bucketName, String objectName) {
|
||||
return amazonS3.getObject(bucketName, objectName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,8 +203,10 @@ public class OssTemplate implements InitializingBean {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterPropertiesSet() {
|
||||
ClientConfiguration clientConfiguration = new ClientConfiguration();
|
||||
clientConfiguration.setMaxConnections(ossProperties.getMaxConnections());
|
||||
|
||||
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
|
||||
ossProperties.getEndpoint(), ossProperties.getRegion());
|
||||
AWSCredentials awsCredentials = new BasicAWSCredentials(ossProperties.getAccessKey(),
|
||||
|
||||
+3
-3
@@ -20,6 +20,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.amazonaws.services.s3.model.S3Object;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysFile;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysFileMapper;
|
||||
@@ -36,7 +37,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -88,9 +88,9 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
|
||||
*/
|
||||
@Override
|
||||
public void getFile(String bucket, String fileName, HttpServletResponse response) {
|
||||
try (InputStream inputStream = minioTemplate.getObject(bucket, fileName)) {
|
||||
try (S3Object s3Object = minioTemplate.getObject(bucket, fileName)) {
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IoUtil.copy(inputStream, response.getOutputStream());
|
||||
IoUtil.copy(s3Object.getObjectContent(), response.getOutputStream());
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("文件读取异常: {}", e.getLocalizedMessage());
|
||||
|
||||
Reference in new issue
Block a user