Skip to content

Commit 72e61ee

Browse files
authored
Fix file uploads (#1715)
This PR fixes the error encountered when using file uploading actions: ["Expected a file url or base64 with mimeType"](https://github.com/openops-cloud/openops/blob/3f3b8285d26d332de896dbc330184130e800bb41/packages/engine/src/lib/variables/props-processor.ts#L196). 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 * Fixes regex rejecting valid mime types such as `application/vnd.ms-visio.drawing` * Fixes the Zod schema check for PropertyType.FILE to check for `WorkflowFile` not `record<>` * Fixes the unit-test that was incorrectly passing due to using the same `displayName` for both test cases which caused the output to contain only 1 error instead of 2. ## Testing Checklist Check all that apply: - [x] I tested the feature thoroughly, including edge cases - [x] I verified all affected areas still work as expected - [x] Automated tests were added/updated if necessary - [x] Changes are backwards compatible with any existing data, otherwise a migration script is provided <!-- This is an auto-generated comment: release notes by coderabbit.ai --> Fixes OPS-3230. ## Summary by CodeRabbit * **Bug Fixes** * Enhanced file data URL processing to support MIME types with extended character formats. * Improved file property validation with stricter type checking for improved reliability. * **Tests** * Updated test naming for improved clarity in file validation scenarios. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 39b378a commit 72e61ee

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

packages/engine/src/lib/variables/processors/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function handleBase64File(propertyValue: string): WorkflowFile | null {
3131
if (!isBase64(propertyValue, { allowMime: true })) {
3232
return null;
3333
}
34-
const matches = propertyValue.match(/^data:([A-Za-z-+/]+);base64,(.+)$/); // example match: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC
34+
const matches = propertyValue.match(/^data:([A-Za-z.+/-]+);base64,(.+)$/); // example match: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC
3535
if (!matches || matches?.length !== 3) {
3636
return null;
3737
}

packages/engine/src/lib/variables/props-processor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
InputPropertyMap,
88
PropertyType,
99
StaticPropsValue,
10+
WorkflowFile,
1011
} from '@openops/blocks-framework';
1112
import { tryParseJson } from '@openops/common';
1213
import { AUTHENTICATION_PROPERTY_NAME, isNil, isObject } from '@openops/shared';
@@ -192,7 +193,7 @@ const validateProperty = (
192193
});
193194
break;
194195
case PropertyType.FILE:
195-
schema = z.record(z.any(), z.any(), {
196+
schema = z.instanceof(WorkflowFile, {
196197
error: `Expected a file url or base64 with mimeType, received: ${originalValue}`,
197198
});
198199
break;

packages/engine/test/services/props-processor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Props Processor', () => {
99
};
1010
const props = {
1111
base64WithMime: Property.File({
12-
displayName: 'Base64',
12+
displayName: 'Base64WithMime',
1313
required: true,
1414
}),
1515
base64: Property.File({

0 commit comments

Comments
 (0)