From 12857ae6a3fb53be360e778fbd6df3819344e765 Mon Sep 17 00:00:00 2001 From: Shenghan Gao Date: Sat, 27 May 2017 23:57:31 -0700 Subject: [PATCH] made maxFileSize in FileUploadController configurable --- README.md | 3 +++ src/main/java/JettyLauncher.java | 3 +++ .../gitbucket/core/controller/FileUploadController.scala | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f865456f..6ee2f0177 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,12 @@ You can specify following options: - `--host=[HOSTNAME]` - `--gitbucket.home=[DATA_DIR]` - `--temp_dir=[TEMP_DIR]` +- `--max_file_size=[MAX_FILE_SIZE]` `TEMP_DIR` is used as the [temporary directory for the jetty application context](https://www.eclipse.org/jetty/documentation/9.3.x/ref-temporary-directories.html). This is the directory into which the `gitbucket.war` file is unpacked, the source files are compiled, etc. If given this parameter **must** match the path of an existing directory or the application will quit reporting an error; if not given the path used will be a `tmp` directory inside the gitbucket home. +`MAX_FILE_SIZE` is the max file size for upload files. + You can also deploy `gitbucket.war` to a servlet container which supports Servlet 3.0 (like Jetty, Tomcat, JBoss, etc) For more information about installation on Mac or Windows Server (with IIS), or configuration of Apache or Nginx and also integration with other tools or services such as Jenkins or Slack, see [Wiki](https://github.com/gitbucket/gitbucket/wiki). diff --git a/src/main/java/JettyLauncher.java b/src/main/java/JettyLauncher.java index 74d280d6e..8b91e913a 100644 --- a/src/main/java/JettyLauncher.java +++ b/src/main/java/JettyLauncher.java @@ -39,6 +39,9 @@ public class JettyLauncher { contextPath = "/" + contextPath; } break; + case "--max_file_size": + System.setProperty("gitbucket.maxFileSize", dim[2]); + break; case "--gitbucket.home": System.setProperty("gitbucket.home", dim[1]); break; diff --git a/src/main/scala/gitbucket/core/controller/FileUploadController.scala b/src/main/scala/gitbucket/core/controller/FileUploadController.scala index b3926fe84..9f27caacd 100644 --- a/src/main/scala/gitbucket/core/controller/FileUploadController.scala +++ b/src/main/scala/gitbucket/core/controller/FileUploadController.scala @@ -22,7 +22,12 @@ import org.apache.commons.io.{FileUtils, IOUtils} */ class FileUploadController extends ScalatraServlet with FileUploadSupport with RepositoryService with AccountService { - configureMultipartHandling(MultipartConfig(maxFileSize = Some(3 * 1024 * 1024))) + val maxFileSize = if (System.getProperty("gitbucket.maxFileSize") != null) + System.getProperty("gitbucket.maxFileSize").toLong + else + 3 * 1024 * 1024 + + configureMultipartHandling(MultipartConfig(maxFileSize = Some(maxFileSize))) post("/image"){ execute({ (file, fileId) =>