Skip to content

Commit c83fe6c

Browse files
committed
max upload size configuration
1 parent c0f3e03 commit c83fe6c

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

framework/src/main/java/com/angkorteam/pluggable/framework/FrameworkConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ public interface FrameworkConstants {
44

55
String REPOSITORY = "repository";
66

7+
String MAX_UPLOAD_SIZE = "max-upload-size";
8+
79
String REPOSITORY_LOCAL_URI = "file://";
810

911
String X_FORWARDED_FOR = "x-forwarded-for";

framework/src/main/java/com/angkorteam/pluggable/framework/page/ApplicationSettingPage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public abstract class ApplicationSettingPage extends KnownPage {
4949
@TextField(label = "Repository", placeholder = "Repository", order = 3)
5050
private String repository;
5151

52+
@Setting(name = FrameworkConstants.MAX_UPLOAD_SIZE)
53+
@TextField(label = "Max Upload Size", placeholder = "MB", order = 4)
54+
@NotNull
55+
private Double maxUploadSize;
56+
5257
@Setting(name = FrameworkConstants.DEBUG)
5358
@CheckBox(label = "Debug Mode", placeholder = "Run in Debug Mode ?", order = 8)
5459
@NotNull

framework/src/main/java/com/angkorteam/pluggable/framework/page/InstallationPage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public final class InstallationPage extends KnownPage {
5656
@com.angkorteam.pluggable.framework.widget.TextField(label = "Repository", placeholder = "Repository", order = 3)
5757
private String repository;
5858

59+
@NotNull
60+
@com.angkorteam.pluggable.framework.widget.TextField(label = "Max Upload Size", placeholder = "MB", order = 4)
61+
private Double maxUploadSize;
62+
5963
public InstallationPage() {
6064
initializeInterceptor();
6165
this.repository = FileUtils.getTempDirectoryPath();
@@ -127,6 +131,7 @@ public void okayClick() {
127131
this.serverAddress);
128132
application.update(FrameworkConstants.DEBUG, false);
129133
application.update(FrameworkConstants.DEPRECATED, false);
134+
application.update(FrameworkConstants.MAX_UPLOAD_SIZE, maxUploadSize);
130135

131136
setResponsePage(MigrationPage.class);
132137
}

framework/src/main/java/com/angkorteam/pluggable/framework/wicket/RestController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ public void respond(Attributes attributes) {
8686
&& request.getHeader("Content-Type").startsWith(
8787
"multipart/form-data")) {
8888
try {
89+
Double maxUploadSize = application.select(
90+
FrameworkConstants.MAX_UPLOAD_SIZE, Double.class);
91+
if (maxUploadSize == null || maxUploadSize <= 0) {
92+
maxUploadSize = 10d;
93+
}
8994
request = ((ServletWebRequest) request).newMultipartWebRequest(
90-
Bytes.megabytes(10), "mp3");
95+
Bytes.megabytes(maxUploadSize),
96+
String.valueOf(System.nanoTime()));
9197
} catch (FileUploadException e) {
9298
}
9399
}

0 commit comments

Comments
 (0)