修改上传限制
This commit is contained in:
parent
bbc4a267be
commit
f7a08cdf09
@ -2,12 +2,13 @@ package com.red.circle.console.adapter.app.party3rd;//package com.sugartime.app.
|
|||||||
|
|
||||||
import com.red.circle.external.inner.endpoint.oss.OssServiceClient;
|
import com.red.circle.external.inner.endpoint.oss.OssServiceClient;
|
||||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -57,23 +58,30 @@ public class AliYunRestController {
|
|||||||
fileHeaders.setContentType(MediaType.parseMediaType(file.getContentType()));
|
fileHeaders.setContentType(MediaType.parseMediaType(file.getContentType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteArrayResource resource = new ByteArrayResource(file.getBytes()) {
|
|
||||||
@Override
|
|
||||||
public String getFilename() {
|
|
||||||
return Objects.toString(file.getOriginalFilename(), "upload.bin");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
|
||||||
body.add("file", new HttpEntity<>(resource, fileHeaders));
|
|
||||||
|
|
||||||
String uploadUrl = externalBaseUrl.replaceAll("/+$", "")
|
String uploadUrl = externalBaseUrl.replaceAll("/+$", "")
|
||||||
+ "/oss/upload/general?dir=" + encode(dir)
|
+ "/oss/upload/general?dir=" + encode(dir)
|
||||||
+ "&filename=" + encode(filename);
|
+ "&filename=" + encode(filename);
|
||||||
ResponseEntity<Map> response = new RestTemplate().postForEntity(
|
ResponseEntity<Map> response;
|
||||||
uploadUrl,
|
try (InputStream inputStream = file.getInputStream()) {
|
||||||
new HttpEntity<>(body, requestHeaders),
|
InputStreamResource resource = new InputStreamResource(inputStream) {
|
||||||
Map.class);
|
@Override
|
||||||
|
public String getFilename() {
|
||||||
|
return Objects.toString(file.getOriginalFilename(), "upload.bin");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long contentLength() {
|
||||||
|
return file.getSize();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||||
|
body.add("file", new HttpEntity<>(resource, fileHeaders));
|
||||||
|
response = new RestTemplate().postForEntity(
|
||||||
|
uploadUrl,
|
||||||
|
new HttpEntity<>(body, requestHeaders),
|
||||||
|
Map.class);
|
||||||
|
}
|
||||||
Map<?, ?> responseBody = response.getBody();
|
Map<?, ?> responseBody = response.getBody();
|
||||||
if (responseBody == null || !Boolean.TRUE.equals(responseBody.get("status"))) {
|
if (responseBody == null || !Boolean.TRUE.equals(responseBody.get("status"))) {
|
||||||
String errorMsg = responseBody == null ? "upload failed"
|
String errorMsg = responseBody == null ? "upload failed"
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class UndertowUploadLimitConfiguration {
|
public class UndertowUploadLimitConfiguration {
|
||||||
|
|
||||||
private static final long MAX_UPLOAD_SIZE_BYTES = 20L * 1024 * 1024;
|
private static final long MAX_UPLOAD_SIZE_BYTES = 500L * 1024 * 1024;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() {
|
public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ server:
|
|||||||
servlet:
|
servlet:
|
||||||
context-path: /console
|
context-path: /console
|
||||||
undertow:
|
undertow:
|
||||||
max-http-post-size: 20MB
|
max-http-post-size: 500MB
|
||||||
no-request-timeout: 60000
|
no-request-timeout: 60000
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
@ -19,9 +19,9 @@ spring:
|
|||||||
dev: dev,web-framework,openfeign,mybatis-plus
|
dev: dev,web-framework,openfeign,mybatis-plus
|
||||||
prod: prod,web-framework,openfeign,mybatis-plus
|
prod: prod,web-framework,openfeign,mybatis-plus
|
||||||
servlet:
|
servlet:
|
||||||
multipart:
|
multipart:
|
||||||
max-file-size: 20MB
|
max-file-size: 500MB
|
||||||
max-request-size: 20MB
|
max-request-size: 500MB
|
||||||
enabled: true
|
enabled: true
|
||||||
---
|
---
|
||||||
spring:
|
spring:
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import java.util.UUID;
|
|||||||
public class OssRestController {
|
public class OssRestController {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(OssRestController.class);
|
private static final Logger log = LoggerFactory.getLogger(OssRestController.class);
|
||||||
private static final long MAX_UPLOAD_SIZE_BYTES = 20L * 1024 * 1024;
|
private static final long MAX_UPLOAD_SIZE_BYTES = 500L * 1024 * 1024;
|
||||||
|
|
||||||
private final AliYunStsService aliYunStsService;
|
private final AliYunStsService aliYunStsService;
|
||||||
private final OssService ossService;
|
private final OssService ossService;
|
||||||
@ -78,7 +78,7 @@ public class OssRestController {
|
|||||||
return ResultResponse.failure(OssErrorCode.FILE_IS_NULL);
|
return ResultResponse.failure(OssErrorCode.FILE_IS_NULL);
|
||||||
}
|
}
|
||||||
if (file.getSize() > MAX_UPLOAD_SIZE_BYTES) {
|
if (file.getSize() > MAX_UPLOAD_SIZE_BYTES) {
|
||||||
return ResultResponse.failure(OssErrorCode.FILE_SIZE_GREATER_THAN_20M);
|
return ResultResponse.failure(OssErrorCode.FILE_SIZE_GREATER_THAN_500M);
|
||||||
}
|
}
|
||||||
String name = file.getOriginalFilename().toLowerCase();
|
String name = file.getOriginalFilename().toLowerCase();
|
||||||
if(!FileUtils.fileContentType(name)) {
|
if(!FileUtils.fileContentType(name)) {
|
||||||
@ -123,7 +123,7 @@ public class OssRestController {
|
|||||||
return ResultResponse.failure(OssErrorCode.FILE_IS_NULL);
|
return ResultResponse.failure(OssErrorCode.FILE_IS_NULL);
|
||||||
}
|
}
|
||||||
if (file.getSize() > MAX_UPLOAD_SIZE_BYTES) {
|
if (file.getSize() > MAX_UPLOAD_SIZE_BYTES) {
|
||||||
return ResultResponse.failure(OssErrorCode.FILE_SIZE_GREATER_THAN_20M);
|
return ResultResponse.failure(OssErrorCode.FILE_SIZE_GREATER_THAN_500M);
|
||||||
}
|
}
|
||||||
String storageKey = buildStorageKey(dir, filename, file.getOriginalFilename());
|
String storageKey = buildStorageKey(dir, filename, file.getOriginalFilename());
|
||||||
if (tencentCosStorageService.isEnabled()) {
|
if (tencentCosStorageService.isEnabled()) {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.red.circle.framework.dto.IResponseErrorCode;
|
|||||||
public enum OssErrorCode implements IResponseErrorCode {
|
public enum OssErrorCode implements IResponseErrorCode {
|
||||||
FILE_IS_NULL(20001, "file is null"),
|
FILE_IS_NULL(20001, "file is null"),
|
||||||
FILE_TYPE_NOT_SUPPORTED(20003, "File type not supported"),
|
FILE_TYPE_NOT_SUPPORTED(20003, "File type not supported"),
|
||||||
FILE_SIZE_GREATER_THAN_20M(20003, "File size greater than 20M"),
|
FILE_SIZE_GREATER_THAN_500M(20003, "File size greater than 500M"),
|
||||||
NETWORK_ANOMALY(20004, "network anomaly");
|
NETWORK_ANOMALY(20004, "network anomaly");
|
||||||
|
|
||||||
private final int code;
|
private final int code;
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class UndertowUploadLimitConfiguration {
|
public class UndertowUploadLimitConfiguration {
|
||||||
|
|
||||||
private static final long MAX_UPLOAD_SIZE_BYTES = 20L * 1024 * 1024;
|
private static final long MAX_UPLOAD_SIZE_BYTES = 500L * 1024 * 1024;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() {
|
public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ server:
|
|||||||
port: 3000
|
port: 3000
|
||||||
shutdown: graceful
|
shutdown: graceful
|
||||||
undertow:
|
undertow:
|
||||||
max-http-post-size: 20MB
|
max-http-post-size: 500MB
|
||||||
no-request-timeout: 60000
|
no-request-timeout: 60000
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
@ -12,8 +12,8 @@ spring:
|
|||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
servlet:
|
servlet:
|
||||||
multipart:
|
multipart:
|
||||||
max-file-size: 20MB
|
max-file-size: 500MB
|
||||||
max-request-size: 20MB
|
max-request-size: 500MB
|
||||||
enabled: true
|
enabled: true
|
||||||
profiles:
|
profiles:
|
||||||
active: @profiles.active@
|
active: @profiles.active@
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user