修改上传限制
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.framework.core.asserts.ResponseAssert;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -57,23 +58,30 @@ public class AliYunRestController {
|
||||
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("/+$", "")
|
||||
+ "/oss/upload/general?dir=" + encode(dir)
|
||||
+ "&filename=" + encode(filename);
|
||||
ResponseEntity<Map> response = new RestTemplate().postForEntity(
|
||||
uploadUrl,
|
||||
new HttpEntity<>(body, requestHeaders),
|
||||
Map.class);
|
||||
ResponseEntity<Map> response;
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
InputStreamResource resource = new InputStreamResource(inputStream) {
|
||||
@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();
|
||||
if (responseBody == null || !Boolean.TRUE.equals(responseBody.get("status"))) {
|
||||
String errorMsg = responseBody == null ? "upload failed"
|
||||
|
||||
@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
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
|
||||
public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() {
|
||||
|
||||
@ -4,7 +4,7 @@ server:
|
||||
servlet:
|
||||
context-path: /console
|
||||
undertow:
|
||||
max-http-post-size: 20MB
|
||||
max-http-post-size: 500MB
|
||||
no-request-timeout: 60000
|
||||
|
||||
spring:
|
||||
@ -19,9 +19,9 @@ spring:
|
||||
dev: dev,web-framework,openfeign,mybatis-plus
|
||||
prod: prod,web-framework,openfeign,mybatis-plus
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB
|
||||
max-request-size: 20MB
|
||||
multipart:
|
||||
max-file-size: 500MB
|
||||
max-request-size: 500MB
|
||||
enabled: true
|
||||
---
|
||||
spring:
|
||||
|
||||
@ -31,7 +31,7 @@ import java.util.UUID;
|
||||
public class OssRestController {
|
||||
|
||||
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 OssService ossService;
|
||||
@ -78,7 +78,7 @@ public class OssRestController {
|
||||
return ResultResponse.failure(OssErrorCode.FILE_IS_NULL);
|
||||
}
|
||||
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();
|
||||
if(!FileUtils.fileContentType(name)) {
|
||||
@ -123,7 +123,7 @@ public class OssRestController {
|
||||
return ResultResponse.failure(OssErrorCode.FILE_IS_NULL);
|
||||
}
|
||||
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());
|
||||
if (tencentCosStorageService.isEnabled()) {
|
||||
|
||||
@ -5,7 +5,7 @@ import com.red.circle.framework.dto.IResponseErrorCode;
|
||||
public enum OssErrorCode implements IResponseErrorCode {
|
||||
FILE_IS_NULL(20001, "file is null"),
|
||||
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");
|
||||
|
||||
private final int code;
|
||||
|
||||
@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
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
|
||||
public WebServerFactoryCustomizer<ConfigurableUndertowWebServerFactory> undertowUploadLimitCustomizer() {
|
||||
|
||||
@ -2,7 +2,7 @@ server:
|
||||
port: 3000
|
||||
shutdown: graceful
|
||||
undertow:
|
||||
max-http-post-size: 20MB
|
||||
max-http-post-size: 500MB
|
||||
no-request-timeout: 60000
|
||||
|
||||
spring:
|
||||
@ -12,8 +12,8 @@ spring:
|
||||
allow-bean-definition-overriding: true
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB
|
||||
max-request-size: 20MB
|
||||
max-file-size: 500MB
|
||||
max-request-size: 500MB
|
||||
enabled: true
|
||||
profiles:
|
||||
active: @profiles.active@
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user