Skip to content

fix: file upload UI issues in Swagger documentation#16

Merged
qowlgur121 merged 3 commits into
developfrom
feature/fix-swagger-markdown-upload
Aug 18, 2025
Merged

fix: file upload UI issues in Swagger documentation#16
qowlgur121 merged 3 commits into
developfrom
feature/fix-swagger-markdown-upload

Conversation

@qowlgur121

Copy link
Copy Markdown
Member

Summary

This PR resolves file upload issues in the Swagger UI where markdown files were being rejected due to inconsistent Content-Type handling betweenå different browsers.
The changes improve both the technical implementation and user documentation for file uploads.

Key Changes

  • Enhanced file type detection: Added intelligent Content-Type resolution that checks both headers and file extensions
  • Improved API documentation: Updated Swagger annotations with clearer descriptions and proper multipart encoding configuration
  • Code quality: Minor formatting cleanup in SearchService

Technical Implementation Notes

  • Implemented resolveContentType() method in FileStorageService to handle browser Content-Type variations
  • Enhanced validateFile() method with canonical content type checking
  • Added fallback logic for generic content types like application/octet-stream
  • Updated Swagger @RequestBody configuration with proper encoding specifications

Testing Instructions

  1. Navigate to /swagger-ui.html in your browser
  2. Locate the file upload endpoint (POST /api/v1/sources/upload)
  3. Test uploading markdown files (.md, .markdown) using the file picker
  4. Verify that uploads complete successfully without validation errors
  5. Test with PDF and text files to ensure backward compatibility

Files Modified

  • FileStorageService.java - Core file validation and type resolution logic
  • DocsSourceController.java - API documentation improvements
  • SearchService.java - Minor formatting cleanup

Related Issues

  • Resolves Swagger UI file upload button responsiveness issues
  • Addresses Content-Type inconsistencies across different browsers
  • Improves developer experience with better API documentation

Key Implementation Notes (1-Minute Report)

  • Pattern: Applied enhanced validation pattern with intelligent type
    resolution
  • Testing: Verified file upload functionality with multiple file types and
    browsers
  • API Docs: Updated Swagger annotations for better multipart form handling
  • Performance: No performance impact, validation remains efficient

Add comprehensive content type resolution logic that properly handles
browser inconsistencies when uploading markdown files. The system now
checks both Content-Type headers and file extensions to determine the
correct file type, ensuring reliable processing regardless of how the
browser sends the multipart data.

Key improvements:
- Enhanced validateFile() method with canonical content type checking
- New resolveContentType() method for intelligent type detection
- Support for .md, .markdown, .txt, and .pdf file extensions
- Fallback logic for generic content types like application/octet-stream

This resolves Swagger UI file upload issues where markdown files
were being rejected due to browser-specific Content-Type variations.
Improve Swagger UI documentation to better guide users through the
file upload process. Added detailed explanations of supported file
types, clarified Content-Type handling, and configured proper
multipart form encoding specifications.

Documentation improvements:
- Expanded file type descriptions with extension examples
- Added note about automatic Content-Type detection
- Configured proper @encoding annotation for multipart forms
- Refined parameter descriptions for better clarity
- Updated RequestBody content specification

These changes improve the developer experience when using the
API documentation and testing file uploads through Swagger UI.
Remove trailing whitespace in search result parsing method
to maintain consistent code formatting standards.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes file upload issues in Swagger UI by implementing intelligent Content-Type resolution for file uploads. The changes address browser inconsistencies when uploading markdown files and improve API documentation clarity.

Key changes:

  • Added intelligent Content-Type resolution that checks both HTTP headers and file extensions
  • Enhanced file validation logic to use canonical content types
  • Improved Swagger documentation with clearer descriptions and proper multipart encoding configuration

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
FileStorageService.java Implements content type resolution logic and updates file validation to handle browser inconsistencies
DocsSourceController.java Updates Swagger annotations with better documentation and proper multipart encoding configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

*/
private String getFileExtension(String filename) {
int lastDot = filename.lastIndexOf('.');
if (lastDot == -1 || lastDot == filename.length() - 1) {

Copilot AI Aug 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition lastDot == filename.length() - 1 will incorrectly return an empty string for files ending with a dot (e.g., 'file.'). This should return the empty string only when there's no extension, but a file ending with a dot should be handled differently or treated as having no valid extension.

Suggested change
if (lastDot == -1 || lastDot == filename.length() - 1) {
// No dot, or dot is the first character (dotfile), or dot is the last character (ends with dot)
if (lastDot <= 0 || lastDot == filename.length() - 1) {

Copilot uses AI. Check for mistakes.
- Plain text files (text/plain, .txt files)

**Note:** The system automatically detects file types based on both the Content-Type header
and file extension. the system will properly recognize Markdown files regardless of how the browser sends the Content-Type.

Copilot AI Aug 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing capitalization: 'the system' should be 'The system' as it starts a new sentence.

Suggested change
and file extension. the system will properly recognize Markdown files regardless of how the browser sends the Content-Type.
and file extension. The system will properly recognize Markdown files regardless of how the browser sends the Content-Type.

Copilot uses AI. Check for mistakes.
}

// Fallback to inbound or generic
return inbound != null ? inbound : "application/octet-stream";

Copilot AI Aug 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback logic returns the original inbound content type for unknown extensions, which could bypass validation. Consider returning a specific unsupported type or logging this case, as it may allow unsupported file types to pass through if they have an unrecognized extension but valid inbound content type.

Suggested change
return inbound != null ? inbound : "application/octet-stream";
default -> {
log.warn("Unknown file extension '{}', treating as unsupported type. Inbound content type: '{}'", ext, inbound);
yield "unsupported/unknown";
}
};
}
// Fallback to unsupported type if extension is missing
log.warn("Unable to determine file extension for filename '{}', treating as unsupported type. Inbound content type: '{}'", filename, inbound);
return "unsupported/unknown";

Copilot uses AI. Check for mistakes.
@qowlgur121
qowlgur121 merged commit 2fa8dae into develop Aug 18, 2025
@Yoo-SH Yoo-SH mentioned this pull request Aug 21, 2025
53 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants