-
Notifications
You must be signed in to change notification settings - Fork 107
feat: add file upload size limit with friendly error messages #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add file upload size limit with friendly error messages #366
Conversation
SpursJiang
commented
Sep 14, 2025
- Add file upload size validation with user-friendly error messages
- Implement HandshakeController to communicate size limits to frontend
- Add GlobalExceptionHandler for handling file size exceeded errors
- Update FileTransferForm to show clear size limit warnings
- Add bilingual documentation for file upload configuration
- Support both English and Chinese error messages
- Add file upload size validation with user-friendly error messages - Implement HandshakeController to communicate size limits to frontend - Add GlobalExceptionHandler for handling file size exceeded errors - Update FileTransferForm to show clear size limit warnings - Add bilingual documentation for file upload configuration - Support both English and Chinese error messages Signed-off-by: jiangpeng <949474720@qq.com>
- Fix test compatibility issue by making MultipartProperties parameter optional - Add null check to prevent NullPointerException in test environments - Ensure file size limit feature works when MultipartProperties is available Signed-off-by: spursjiang <949474720@qq.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements configurable file upload size limits with comprehensive user experience improvements. It adds dynamic size validation, friendly error messages in both English and Chinese, and seamless communication between backend configuration and frontend interface.
- Dynamic file size limit configuration retrieved from backend via handshake API
- Comprehensive file upload error handling with size-specific messages
- Frontend validation with immediate feedback and bilingual support
Reviewed Changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
site/docs/zh/guide/file-upload-configuration.md | New comprehensive Chinese documentation for file upload configuration |
site/docs/zh/guide/configuration.md | Added Chinese documentation for multipart configuration properties |
site/docs/guide/file-upload-configuration.md | New comprehensive English documentation for file upload configuration |
site/docs/guide/configuration.md | Added English documentation for multipart configuration properties |
site/docs/guide/changelog.md | Updated changelog with file upload enhancement features |
server/src/main/java/org/eclipse/jifa/server/util/ErrorUtil.java | Added utility method for creating structured error responses |
server/src/main/java/org/eclipse/jifa/server/enums/ServerErrorCode.java | Added FILE_TOO_LARGE error code for file size violations |
server/src/main/java/org/eclipse/jifa/server/domain/dto/HandshakeResponse.java | Extended handshake response to include maximum file size configuration |
server/src/main/java/org/eclipse/jifa/server/controller/HandshakeController.java | Enhanced controller to communicate file size limits to frontend |
server/src/main/java/org/eclipse/jifa/server/controller/GlobalExceptionHandler.java | Added comprehensive file upload size exception handling |
frontend/src/stores/env.ts | Added file size limit storage and management in environment store |
frontend/src/i18n/zh.ts | Added Chinese translations for file upload messages |
frontend/src/i18n/en.ts | Added English translations for file upload messages |
frontend/src/components/forms/FileTransferForm.vue | Enhanced upload form with size validation and error handling |
analysis/gc-log/src/test/java/org/eclipse/jifa/gclog/TestFragmentedParserToMetrics.java | Fixed comma placement in printf statement |
analysis/gc-log/src/main/java/org/eclipse/jifa/gclog/parser/AbstractPreUnifiedGCLogParser.java | Fixed parenthesis character in comment |
Files not reviewed (1)
- frontend/package-lock.json: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
server/src/main/java/org/eclipse/jifa/server/controller/HandshakeController.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/eclipse/jifa/server/controller/GlobalExceptionHandler.java
Outdated
Show resolved
Hide resolved
eca has passed. |
- Fix null MultipartProperties handling in HandshakeController - Simplify fragile string parsing in GlobalExceptionHandler - Improve error.response type safety in FileTransferForm
Thanks for the suggestions! I've addressed all issues。 |
Could you please merge my pull request? |
} | ||
// Format file size | ||
function formatFileSize(bytes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can reuse the simmilar function in
jifa/frontend/src/support/utils.ts
Line 21 in 287dfb8
export function prettySize(size: number): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,done
frontend/src/stores/env.ts
Outdated
|
||
disabledFileTransferMethods: [] | ||
disabledFileTransferMethods: [], | ||
maxFileSize: 536870912 // Default 512MB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlimited size for the default may be a better choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,done
frontend/src/support/utils.ts
Outdated
import {formatDate} from '@vueuse/core'; | ||
import {ElNotification} from 'element-plus'; | ||
import {h} from 'vue'; | ||
import { useI18n } from 'vue-i18n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imported but not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,done
/** | ||
* Default maximum file size limit (512MB) - matches Spring Boot's default | ||
*/ | ||
long DEFAULT_MAX_FILE_SIZE_BYTES = 512L * 1024L * 1024L; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlimited size for the default may be a better choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,done
@@ -1,5 +1,5 @@ | |||
/******************************************************************************** | |||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | |||
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024 -> 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
int exp = (int) (Math.log(bytes) / Math.log(1024)); | ||
String pre = "KMGTPE".charAt(exp - 1) + ""; | ||
return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we already have a similar method in our Java code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,done
/** | ||
* Handle file upload size exceeded exceptions with simple, reliable error message | ||
*/ | ||
private void handleFileUploadSizeExceeded(MaxUploadSizeExceededException e, HttpServletResponse response) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to handle this exception especially?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this achieves:
Automatic interception: When Spring MVC throws MaxUploadSizeExceededException, our handler catches it immediately
User-friendly response: Returns a structured error with FILE_TOO_LARGE error code and formatted file size
Frontend integration: Provides the exact data needed for frontend internationalization
Proper HTTP status: Returns 413 (Payload Too Large) status code following HTTP standards
Logging for debugging: Captures detailed information for troubleshooting while keeping user-facing messages clean
config.getDisabledFileTransferMethods(), | ||
user); | ||
user, | ||
maxFileSizeBytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If maxFileSizeBytes
only limits the files uploaded through web pages, I think we should use a more appropriate name, like maxUploadSize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,done
return json.toString().getBytes(Constant.CHARSET); | ||
} | ||
|
||
public static byte[] toJson(ErrorCode errorCode, String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we reuse the method: public static byte[] toJson(Throwable throwable)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,done
Hi, sorry for the late response. I left some comments for this patch. Thanks for the contribution. |
…back - Remove duplicate formatFileSize function, reuse existing prettySize utility - Use unlimited size as default instead of hardcoded 512MB limit - Update copyright year to 2025 in GlobalExceptionHandler - Replace custom formatFileSize with Apache Commons FileUtils.byteCountToDisplaySize - Rename maxFileSizeBytes to maxUploadSize for better clarity - Refactor ErrorUtil.toJson to eliminate code duplication with shared buildJsonBytes method - Simplify file upload error handling logic to use 200 status code - Remove unused imports and clean up code structure - Ensure consistent configuration logic between HandshakeController and GlobalExceptionHandler
Thanks for the suggestions! I've addressed all issues。Could you please merge my pull request?
Thanks for the suggestions! I've addressed all issues。Could you please merge my pull request? |