Fix file uploads#1715
Conversation
…accept dot character
WalkthroughUpdates file validation logic by modifying the Base64 data URL regex to accept MIME types with dots, replacing generic object validation with strict Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
Greptile OverviewGreptile SummaryFixed file upload validation that was incorrectly rejecting valid MIME types and file instances. The PR addresses three interconnected issues:
The changes are minimal, focused, and directly address the root causes identified in the issue. Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant PropsProcessor
participant FileProcessor
participant Validator
User->>PropsProcessor: Upload file (base64 or URL)
PropsProcessor->>FileProcessor: Process file input
alt Base64 with MIME type
FileProcessor->>FileProcessor: Check isBase64()
FileProcessor->>FileProcessor: Match regex pattern
Note over FileProcessor: Fixed regex now includes dot<br/>to support MIME types like<br/>application/vnd.ms-visio.drawing
FileProcessor->>FileProcessor: Extract MIME type and base64 data
FileProcessor->>FileProcessor: Create WorkflowFile instance
FileProcessor-->>PropsProcessor: Return WorkflowFile
else URL
FileProcessor->>FileProcessor: Download from URL
FileProcessor->>FileProcessor: Create WorkflowFile instance
FileProcessor-->>PropsProcessor: Return WorkflowFile
end
PropsProcessor->>Validator: Validate processed value
Validator->>Validator: Check instanceof WorkflowFile
Note over Validator: Fixed validation changed from<br/>z.record() to z.instanceof(WorkflowFile)<br/>for proper type checking
alt Valid WorkflowFile
Validator-->>PropsProcessor: Validation passed
PropsProcessor-->>User: Success
else Invalid type
Validator-->>PropsProcessor: Error message
PropsProcessor-->>User: Error: Expected WorkflowFile
end
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/engine/src/lib/variables/processors/file.ts (1)
31-40: Regex fix looks good; consider supporting digits in MIME typesAllowing
.in the MIME portion correctly enables data URLs likeapplication/vnd.ms-visio.drawingwhile keeping the regex anchored and safe.Since you’re already touching this, consider also allowing digits in the MIME token to cover common types with numeric suffixes (e.g.
...macroenabled.12), which are still rejected today:- const matches = propertyValue.match(/^data:([A-Za-z.+/-]+);base64,(.+)$/); + const matches = propertyValue.match(/^data:([A-Za-z0-9.+/-]+);base64,(.+)$/);This would broaden compatibility without changing the rest of the logic.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/engine/src/lib/variables/processors/file.ts(1 hunks)packages/engine/src/lib/variables/props-processor.ts(2 hunks)packages/engine/test/services/props-processor.test.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/coding-guidelines.mdc)
**/*.{ts,tsx,js,jsx}: Indentation: 2 spaces for TypeScript/JavaScript
Braces required for all control blocks, even single-line
One space between keywords and parentheses:if (condition) {
Use camelCase for variables and functions
Use PascalCase for classes and types
Use UPPER_SNAKE_CASE for constants
Use lowercase with hyphens for file names (e.g.,user-profile.ts)
Preferconstoverletorvarin TypeScript/JavaScript
Prefer arrow functions for callbacks and functional components in TypeScript/JavaScript
Files:
packages/engine/src/lib/variables/processors/file.tspackages/engine/src/lib/variables/props-processor.tspackages/engine/test/services/props-processor.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/coding-guidelines.mdc)
**/*.{ts,tsx}: Use types and interfaces where appropriate in TypeScript
Use explicit return types for exported functions in TypeScript
Files:
packages/engine/src/lib/variables/processors/file.tspackages/engine/src/lib/variables/props-processor.tspackages/engine/test/services/props-processor.test.ts
**/*.{tsx,ts}
📄 CodeRabbit inference engine (.cursor/rules/coding-guidelines.mdc)
**/*.{tsx,ts}: Frontend tech stack must strictly use: React 18, Zustand, react-query v5, shadcn, and Axios withqspackage for query strings
Follow best practices for React hooks
Prefer small, composable components and extract helper functions where possible
Usecnutility to group tailwind classnames in React components
Files:
packages/engine/src/lib/variables/processors/file.tspackages/engine/src/lib/variables/props-processor.tspackages/engine/test/services/props-processor.test.ts
🧬 Code graph analysis (1)
packages/engine/src/lib/variables/props-processor.ts (1)
packages/blocks/framework/src/lib/property/index.ts (1)
WorkflowFile(39-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Engine Image for amd64
- GitHub Check: Build Engine Image for arm64
- GitHub Check: Build App Image for arm64
- GitHub Check: Build App Image for amd64
- GitHub Check: Test Server API
🔇 Additional comments (2)
packages/engine/test/services/props-processor.test.ts (1)
11-32: Distinct displayName prevents future FILE error-key collisionsRenaming the
base64WithMimeproperty’sdisplayNameto'Base64WithMime'keeps its error key distinct from the'Base64'property, so if both ever fail validation they won’t overwrite each other in theerrorsmap (which is keyed bydisplayName). Current expectations (onlyBase64error) remain correct sincebase64WithMimeis valid here.packages/engine/src/lib/variables/props-processor.ts (1)
1-11: VerifyWorkflowFileimport consistency across all construction sitesSwitching the FILE schema from a generic record to
z.instanceof(WorkflowFile, ...)tightens validation so only trueWorkflowFileinstances pass validation, preventing arbitrary objects from being treated as valid files. This is a solid improvement if all code paths that populate FILE props use the sameWorkflowFileclass from@openops/blocks-framework.However, if different modules construct
WorkflowFileinstances without importing from the same source, or if test code manually creates objects, theinstanceofcheck will fail even for structurally identical objects. Confirm that every construction site—includingapFileUtils.readWorkflowFileand any test/block code that creates file values—imports and usesWorkflowFilefrom@openops/blocks-framework.



This PR fixes the error encountered when using file uploading actions: "Expected a file url or base64 with mimeType".
The error occurs even for valid file uploads due incorrect regex and schema checks. The issue was not detected due to a faulty unit test which is also addressed by this PR.
Additional Notes
application/vnd.ms-visio.drawingWorkflowFilenotrecord<>displayNamefor both test cases which caused the output to contain only 1 error instead of 2.Testing Checklist
Check all that apply:
I tested the feature thoroughly, including edge cases
I verified all affected areas still work as expected
Automated tests were added/updated if necessary
Changes are backwards compatible with any existing data, otherwise a migration script is provided
Fixes OPS-3230.
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.