Skip to content

Commit 2bba201

Browse files
authored
fix(file-upload): fixed file upload URL required (#875)
* fix(file-upload): fixed file upload URL required * cleanup
1 parent 64cd60d commit 2bba201

File tree

2 files changed

+73
-117
lines changed

2 files changed

+73
-117
lines changed

apps/sim/blocks/blocks/file.ts

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,63 @@
11
import { DocumentIcon } from '@/components/icons'
2-
import { isProd } from '@/lib/environment'
32
import { createLogger } from '@/lib/logs/console/logger'
4-
import type { BlockConfig, SubBlockConfig, SubBlockLayout, SubBlockType } from '@/blocks/types'
3+
import type { BlockConfig, SubBlockLayout, SubBlockType } from '@/blocks/types'
54
import type { FileParserOutput } from '@/tools/file/types'
65

76
const logger = createLogger('FileBlock')
87

9-
const shouldEnableURLInput = isProd
10-
11-
const inputMethodBlock: SubBlockConfig = {
12-
id: 'inputMethod',
13-
title: 'Select Input Method',
14-
type: 'dropdown' as SubBlockType,
15-
layout: 'full' as SubBlockLayout,
16-
options: [
17-
{ id: 'url', label: 'File URL' },
18-
{ id: 'upload', label: 'Upload Files' },
19-
],
20-
}
21-
22-
const fileUploadBlock: SubBlockConfig = {
23-
id: 'file',
24-
title: 'Upload Files',
25-
type: 'file-upload' as SubBlockType,
26-
layout: 'full' as SubBlockLayout,
27-
acceptedTypes: '.pdf,.csv,.docx',
28-
multiple: true,
29-
maxSize: 100, // 100MB max via direct upload
30-
}
31-
328
export const FileBlock: BlockConfig<FileParserOutput> = {
339
type: 'file',
3410
name: 'File',
3511
description: 'Read and parse multiple files',
36-
longDescription: `Upload and extract contents from structured file formats including PDFs, CSV spreadsheets, and Word documents (DOCX). ${
37-
shouldEnableURLInput
38-
? 'You can either provide a URL to a file or upload files directly. '
39-
: 'Upload files directly. '
40-
}Specialized parsers extract text and metadata from each format. You can upload multiple files at once and access them individually or as a combined document.`,
12+
longDescription: `Upload and extract contents from structured file formats including PDFs, CSV spreadsheets, and Word documents (DOCX). You can either provide a URL to a file or upload files directly. Specialized parsers extract text and metadata from each format. You can upload multiple files at once and access them individually or as a combined document.`,
4113
docsLink: 'https://docs.sim.ai/tools/file',
4214
category: 'tools',
4315
bgColor: '#40916C',
4416
icon: DocumentIcon,
4517
subBlocks: [
46-
...(shouldEnableURLInput ? [inputMethodBlock] : []),
18+
{
19+
id: 'inputMethod',
20+
title: 'Select Input Method',
21+
type: 'dropdown' as SubBlockType,
22+
layout: 'full' as SubBlockLayout,
23+
options: [
24+
{ id: 'url', label: 'File URL' },
25+
{ id: 'upload', label: 'Upload Files' },
26+
],
27+
},
4728
{
4829
id: 'filePath',
4930
title: 'File URL',
5031
type: 'short-input' as SubBlockType,
5132
layout: 'full' as SubBlockLayout,
5233
placeholder: 'Enter URL to a file (https://example.com/document.pdf)',
53-
...(shouldEnableURLInput
54-
? {
55-
condition: {
56-
field: 'inputMethod',
57-
value: 'url',
58-
},
59-
}
60-
: {}),
34+
condition: {
35+
field: 'inputMethod',
36+
value: 'url',
37+
},
6138
},
6239

6340
{
64-
...fileUploadBlock,
65-
...(shouldEnableURLInput ? { condition: { field: 'inputMethod', value: 'upload' } } : {}),
41+
id: 'file',
42+
title: 'Upload Files',
43+
type: 'file-upload' as SubBlockType,
44+
layout: 'full' as SubBlockLayout,
45+
acceptedTypes: '.pdf,.csv,.docx',
46+
multiple: true,
47+
condition: {
48+
field: 'inputMethod',
49+
value: 'upload',
50+
},
51+
maxSize: 100, // 100MB max via direct upload
6652
},
6753
],
6854
tools: {
6955
access: ['file_parser'],
7056
config: {
7157
tool: () => 'file_parser',
7258
params: (params) => {
73-
// Determine input method based on whether URL input is enabled
74-
const inputMethod = shouldEnableURLInput ? params.inputMethod || 'url' : 'upload'
59+
// Determine input method - default to 'url' if not specified
60+
const inputMethod = params.inputMethod || 'url'
7561

7662
if (inputMethod === 'url') {
7763
if (!params.filePath || params.filePath.trim() === '') {
@@ -87,7 +73,7 @@ export const FileBlock: BlockConfig<FileParserOutput> = {
8773
}
8874
}
8975

90-
// Handle file upload input (always possible, default if URL input disabled)
76+
// Handle file upload input
9177
if (inputMethod === 'upload') {
9278
// Handle case where 'file' is an array (multiple files)
9379
if (params.file && Array.isArray(params.file) && params.file.length > 0) {
@@ -109,7 +95,7 @@ export const FileBlock: BlockConfig<FileParserOutput> = {
10995

11096
// If no files, return error
11197
logger.error('No files provided for upload method')
112-
throw new Error('Please upload a file') // Changed error message slightly
98+
throw new Error('Please upload a file')
11399
}
114100

115101
// This part should ideally not be reached if logic above is correct
@@ -119,15 +105,9 @@ export const FileBlock: BlockConfig<FileParserOutput> = {
119105
},
120106
},
121107
inputs: {
122-
// Conditionally require inputMethod and filePath only if URL input is enabled
123-
...(shouldEnableURLInput
124-
? {
125-
inputMethod: { type: 'string', description: 'Input method selection' }, // Not strictly required as it defaults
126-
filePath: { type: 'string', description: 'File URL path' }, // Required only if inputMethod is 'url' (validated in params)
127-
}
128-
: {}),
108+
inputMethod: { type: 'string', description: 'Input method selection' },
109+
filePath: { type: 'string', description: 'File URL path' },
129110
fileType: { type: 'string', description: 'File type' },
130-
// File input is always potentially needed, but only required if method is 'upload' (validated in params)
131111
file: { type: 'json', description: 'Uploaded file data' },
132112
},
133113
outputs: {

apps/sim/blocks/blocks/mistral_parse.ts

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,55 @@
11
import { MistralIcon } from '@/components/icons'
2-
import { isProd } from '@/lib/environment'
3-
import type { BlockConfig, SubBlockConfig, SubBlockLayout, SubBlockType } from '@/blocks/types'
2+
import type { BlockConfig, SubBlockLayout, SubBlockType } from '@/blocks/types'
43
import type { MistralParserOutput } from '@/tools/mistral/types'
54

6-
const shouldEnableFileUpload = isProd
7-
8-
const inputMethodBlock: SubBlockConfig = {
9-
id: 'inputMethod',
10-
title: 'Select Input Method',
11-
type: 'dropdown' as SubBlockType,
12-
layout: 'full' as SubBlockLayout,
13-
options: [
14-
{ id: 'url', label: 'PDF Document URL' },
15-
{ id: 'upload', label: 'Upload PDF Document' },
16-
],
17-
}
18-
19-
const fileUploadBlock: SubBlockConfig = {
20-
id: 'fileUpload',
21-
title: 'Upload PDF',
22-
type: 'file-upload' as SubBlockType,
23-
layout: 'full' as SubBlockLayout,
24-
acceptedTypes: 'application/pdf',
25-
condition: {
26-
field: 'inputMethod',
27-
value: 'upload',
28-
},
29-
maxSize: 50, // 50MB max via direct upload
30-
}
31-
325
export const MistralParseBlock: BlockConfig<MistralParserOutput> = {
336
type: 'mistral_parse',
347
name: 'Mistral Parser',
358
description: 'Extract text from PDF documents',
36-
longDescription: `Extract text and structure from PDF documents using Mistral's OCR API.${
37-
shouldEnableFileUpload
38-
? ' Either enter a URL to a PDF document or upload a PDF file directly.'
39-
: ' Enter a URL to a PDF document (.pdf extension required).'
40-
} Configure processing options and get the content in your preferred format. For URLs, they must be publicly accessible and point to a valid PDF file. Note: Google Drive, Dropbox, and other cloud storage links are not supported; use a direct download URL from a web server instead.`,
9+
longDescription: `Extract text and structure from PDF documents using Mistral's OCR API. Either enter a URL to a PDF document or upload a PDF file directly. Configure processing options and get the content in your preferred format. For URLs, they must be publicly accessible and point to a valid PDF file. Note: Google Drive, Dropbox, and other cloud storage links are not supported; use a direct download URL from a web server instead.`,
4110
docsLink: 'https://docs.sim.ai/tools/mistral_parse',
4211
category: 'tools',
4312
bgColor: '#000000',
4413
icon: MistralIcon,
4514
subBlocks: [
46-
// Show input method selection only if file upload is available
47-
...(shouldEnableFileUpload ? [inputMethodBlock] : []),
15+
// Show input method selection
16+
{
17+
id: 'inputMethod',
18+
title: 'Select Input Method',
19+
type: 'dropdown' as SubBlockType,
20+
layout: 'full' as SubBlockLayout,
21+
options: [
22+
{ id: 'url', label: 'PDF Document URL' },
23+
{ id: 'upload', label: 'Upload PDF Document' },
24+
],
25+
},
4826

49-
// URL input - always shown, but conditional on inputMethod in production
27+
// URL input - conditional on inputMethod
5028
{
5129
id: 'filePath',
5230
title: 'PDF Document URL',
5331
type: 'short-input' as SubBlockType,
5432
layout: 'full' as SubBlockLayout,
5533
placeholder: 'Enter full URL to a PDF document (https://example.com/document.pdf)',
56-
required: !shouldEnableFileUpload,
57-
...(shouldEnableFileUpload
58-
? {
59-
condition: {
60-
field: 'inputMethod',
61-
value: 'url',
62-
},
63-
}
64-
: {}),
34+
condition: {
35+
field: 'inputMethod',
36+
value: 'url',
37+
},
6538
},
6639

67-
// File upload option - only shown in production environments
68-
...(shouldEnableFileUpload ? [fileUploadBlock] : []),
40+
// File upload option
41+
{
42+
id: 'fileUpload',
43+
title: 'Upload PDF',
44+
type: 'file-upload' as SubBlockType,
45+
layout: 'full' as SubBlockLayout,
46+
acceptedTypes: 'application/pdf',
47+
condition: {
48+
field: 'inputMethod',
49+
value: 'upload',
50+
},
51+
maxSize: 50, // 50MB max via direct upload
52+
},
6953

7054
{
7155
id: 'resultType',
@@ -136,27 +120,19 @@ export const MistralParseBlock: BlockConfig<MistralParserOutput> = {
136120
resultType: params.resultType || 'markdown',
137121
}
138122

139-
// Set filePath or fileUpload based on input method (or directly use filePath if no method selector)
140-
if (shouldEnableFileUpload) {
141-
const inputMethod = params.inputMethod || 'url'
142-
if (inputMethod === 'url') {
143-
if (!params.filePath || params.filePath.trim() === '') {
144-
throw new Error('PDF Document URL is required')
145-
}
146-
parameters.filePath = params.filePath.trim()
147-
} else if (inputMethod === 'upload') {
148-
if (!params.fileUpload) {
149-
throw new Error('Please upload a PDF document')
150-
}
151-
// Pass the entire fileUpload object to the tool
152-
parameters.fileUpload = params.fileUpload
153-
}
154-
} else {
155-
// In local development, only URL input is available
123+
// Set filePath or fileUpload based on input method
124+
const inputMethod = params.inputMethod || 'url'
125+
if (inputMethod === 'url') {
156126
if (!params.filePath || params.filePath.trim() === '') {
157127
throw new Error('PDF Document URL is required')
158128
}
159129
parameters.filePath = params.filePath.trim()
130+
} else if (inputMethod === 'upload') {
131+
if (!params.fileUpload) {
132+
throw new Error('Please upload a PDF document')
133+
}
134+
// Pass the entire fileUpload object to the tool
135+
parameters.fileUpload = params.fileUpload
160136
}
161137

162138
// Convert pages input from string to array of numbers if provided

0 commit comments

Comments
 (0)