将可上传文件扩大至500MB

This commit is contained in:
yoyuzh
2026-03-19 10:43:05 +08:00
parent e0d859bd82
commit 64e146dfee
3 changed files with 20 additions and 5 deletions

View File

@@ -8,7 +8,7 @@ public class FileStorageProperties {
private String provider = "local"; private String provider = "local";
private final Local local = new Local(); private final Local local = new Local();
private final Oss oss = new Oss(); private final Oss oss = new Oss();
private long maxFileSize = 50 * 1024 * 1024L; private long maxFileSize = 500L * 1024 * 1024L;
public String getProvider() { public String getProvider() {
return provider; return provider;

View File

@@ -18,8 +18,8 @@ spring:
format_sql: true format_sql: true
servlet: servlet:
multipart: multipart:
max-file-size: 50MB max-file-size: 500MB
max-request-size: 50MB max-request-size: 500MB
app: app:
jwt: jwt:
@@ -27,7 +27,7 @@ app:
expiration-seconds: 86400 expiration-seconds: 86400
storage: storage:
root-dir: ./storage root-dir: ./storage
max-file-size: 52428800 max-file-size: 524288000
cqu: cqu:
base-url: https://example-cqu-api.local base-url: https://example-cqu-api.local
require-login: true require-login: true

View File

@@ -42,7 +42,7 @@ class FileServiceTest {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
FileStorageProperties properties = new FileStorageProperties(); FileStorageProperties properties = new FileStorageProperties();
properties.setMaxFileSize(50 * 1024 * 1024); properties.setMaxFileSize(500L * 1024 * 1024);
fileService = new FileService(storedFileRepository, fileContentStorage, properties); fileService = new FileService(storedFileRepository, fileContentStorage, properties);
} }
@@ -80,6 +80,21 @@ class FileServiceTest {
verify(fileContentStorage).prepareUpload(7L, "/docs", "notes.txt", "text/plain", 12L); verify(fileContentStorage).prepareUpload(7L, "/docs", "notes.txt", "text/plain", 12L);
} }
@Test
void shouldAllowInitiatingUploadAtFiveHundredMegabytes() {
User user = createUser(7L);
long uploadSize = 500L * 1024 * 1024;
when(storedFileRepository.existsByUserIdAndPathAndFilename(7L, "/docs", "movie.zip")).thenReturn(false);
when(fileContentStorage.prepareUpload(7L, "/docs", "movie.zip", "application/zip", uploadSize))
.thenReturn(new PreparedUpload(true, "https://upload.example.com", "PUT", Map.of(), "movie.zip"));
InitiateUploadResponse response = fileService.initiateUpload(user,
new InitiateUploadRequest("/docs", "movie.zip", "application/zip", uploadSize));
assertThat(response.direct()).isTrue();
verify(fileContentStorage).prepareUpload(7L, "/docs", "movie.zip", "application/zip", uploadSize);
}
@Test @Test
void shouldCompleteDirectUploadAndPersistMetadata() { void shouldCompleteDirectUploadAndPersistMetadata() {
User user = createUser(7L); User user = createUser(7L);