Skip to content

Commit 950e055

Browse files
authored
fix(file-upload): re-enabled file upload for mistral & url for file upload (#408)
* re-enabled file upload for mistral & url for file upload * consolidated env checks
1 parent 79b761c commit 950e055

File tree

6 files changed

+21
-53
lines changed

6 files changed

+21
-53
lines changed

apps/sim/.env.example

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,3 @@ ENCRYPTION_KEY=your_encryption_key # Use `openssl rand -hex 32` to generate
1414

1515
# Freestyle API Key (Required for sandboxed code execution for functions/custom-tools)
1616
# FREESTYLE_API_KEY= # Uncomment and add your key from https://docs.freestyle.sh/Getting-Started/run
17-
18-
# S3 Storage Configuration (Optional)
19-
# Set USE_S3=true to enable S3 storage in development
20-
# USE_S3=true
21-
22-
# AWS Credentials (Required when USE_S3=true)
23-
# AWS_ACCESS_KEY_ID=your-access-key-id
24-
# AWS_SECRET_ACCESS_KEY=your-secret-access-key
25-
26-
# S3 Configuration (Required when USE_S3=true)
27-
# S3_BUCKET_NAME=your-bucket-name
28-
# AWS_REGION=us-east-1
29-
30-
# Optional: Custom S3 Base URL (for custom domains or non-AWS S3-compatible storage)
31-
# S3_BASE_URL=https://your-custom-domain.com

apps/sim/app/api/files/delete/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { NextRequest } from 'next/server'
55
import { createLogger } from '@/lib/logs/console-logger'
66
import { deleteFromS3 } from '@/lib/uploads/s3-client'
77
import { UPLOAD_DIR, USE_S3_STORAGE } from '@/lib/uploads/setup'
8-
// Import to ensure the uploads directory is created
98
import '@/lib/uploads/setup.server'
109

1110
import {

apps/sim/blocks/blocks/file.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@ import type { BlockConfig, SubBlockConfig, SubBlockLayout, SubBlockType } from '
66

77
const logger = createLogger('FileBlock')
88

9-
// Create a safe client-only env subset to avoid server-side env access errors
10-
const clientEnv = {
11-
USE_S3: process.env.USE_S3,
12-
}
13-
14-
const isS3Enabled = clientEnv.USE_S3
15-
const shouldEnableURLInput = isProd || isS3Enabled
9+
const shouldEnableURLInput = isProd
1610

17-
// Define sub-blocks conditionally
1811
const inputMethodBlock: SubBlockConfig = {
1912
id: 'inputMethod',
2013
title: 'Select Input Method',
@@ -26,18 +19,6 @@ const inputMethodBlock: SubBlockConfig = {
2619
],
2720
}
2821

29-
const fileUrlBlock: SubBlockConfig = {
30-
id: 'filePath',
31-
title: 'File URL',
32-
type: 'short-input' as SubBlockType,
33-
layout: 'full' as SubBlockLayout,
34-
placeholder: 'Enter URL to a file (https://example.com/document.pdf)',
35-
condition: {
36-
field: 'inputMethod',
37-
value: 'url',
38-
},
39-
}
40-
4122
const fileUploadBlock: SubBlockConfig = {
4223
id: 'file',
4324
title: 'Upload Files',
@@ -62,7 +43,23 @@ export const FileBlock: BlockConfig<FileParserOutput> = {
6243
bgColor: '#40916C',
6344
icon: DocumentIcon,
6445
subBlocks: [
65-
...(shouldEnableURLInput ? [inputMethodBlock, fileUrlBlock] : []),
46+
...(shouldEnableURLInput ? [inputMethodBlock] : []),
47+
{
48+
id: 'filePath',
49+
title: 'File URL',
50+
type: 'short-input' as SubBlockType,
51+
layout: 'full' as SubBlockLayout,
52+
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+
: {}),
61+
},
62+
6663
{
6764
...fileUploadBlock,
6865
...(shouldEnableURLInput ? { condition: { field: 'inputMethod', value: 'upload' } } : {}),

apps/sim/blocks/blocks/mistral_parse.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@ import { isProd } from '@/lib/environment'
33
import type { MistralParserOutput } from '@/tools/mistral/types'
44
import type { BlockConfig, SubBlockConfig, SubBlockLayout, SubBlockType } from '../types'
55

6-
// Create a safe client-only env subset to avoid server-side env access errors
7-
const clientEnv = {
8-
USE_S3: process.env.USE_S3,
9-
}
10-
11-
const isS3Enabled = clientEnv.USE_S3
12-
const shouldEnableFileUpload = isProd || isS3Enabled
6+
const shouldEnableFileUpload = isProd
137

14-
// Define the input method selector block when needed
158
const inputMethodBlock: SubBlockConfig = {
169
id: 'inputMethod',
1710
title: 'Select Input Method',
@@ -23,7 +16,6 @@ const inputMethodBlock: SubBlockConfig = {
2316
],
2417
}
2518

26-
// Define the file upload block when needed
2719
const fileUploadBlock: SubBlockConfig = {
2820
id: 'fileUpload',
2921
title: 'Upload PDF',

apps/sim/lib/env.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export const env = createEnv({
6666
AWS_SECRET_ACCESS_KEY: z.string().optional(),
6767
S3_BUCKET_NAME: z.string().optional(),
6868
S3_LOGS_BUCKET_NAME: z.string().optional(),
69-
USE_S3: z.coerce.boolean().optional(),
7069
CRON_SECRET: z.string().optional(),
7170
FREE_PLAN_LOG_RETENTION_DAYS: z.string().optional(),
7271
NODE_ENV: z.string().optional(),

apps/sim/lib/uploads/setup.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
import { existsSync } from 'fs'
22
import { mkdir } from 'fs/promises'
33
import path, { join } from 'path'
4+
import { isProd } from '@/lib/environment'
45
import { createLogger } from '@/lib/logs/console-logger'
56
import { env } from '../env'
67

78
const logger = createLogger('UploadsSetup')
89

9-
// Define project root - this works regardless of how the app is started
1010
const PROJECT_ROOT = path.resolve(process.cwd())
1111

12-
// Define the upload directory path using project root
1312
export const UPLOAD_DIR = join(PROJECT_ROOT, 'uploads')
1413

15-
export const USE_S3_STORAGE = env.NODE_ENV === 'production' || env.USE_S3
14+
export const USE_S3_STORAGE = isProd
1615

1716
export const S3_CONFIG = {
1817
bucket: env.S3_BUCKET_NAME || '',
1918
region: env.AWS_REGION || '',
2019
}
2120

22-
/**
23-
* Ensures that the uploads directory exists (for local storage)
24-
*/
2521
export async function ensureUploadsDirectory() {
2622
if (USE_S3_STORAGE) {
2723
logger.info('Using S3 storage, skipping local uploads directory creation')

0 commit comments

Comments
 (0)