Skip to content

Commit 11907c6

Browse files
committed
fix(uploads): cap formdata fallback at 100MB; drop unused size param
1 parent 7101c7e commit 11907c6

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

apps/sim/app/api/workspaces/[id]/files/register/route.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ describe('POST /api/workspaces/[id]/files/register', () => {
170170
key: VALID_KEY,
171171
originalName: 'video.mp4',
172172
contentType: 'video/mp4',
173-
size: 10 * 1024 * 1024,
174173
})
175174

176175
expect(posthogServerMockFns.mockCaptureServerEvent).toHaveBeenCalledWith(

apps/sim/app/api/workspaces/[id]/files/register/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const POST = withRouteHandler(
3333
if (!parsed.success) return parsed.response
3434
const { params, body } = parsed.data
3535
const workspaceId = params.id
36-
const { key, name, size, contentType } = body
36+
const { key, name, contentType } = body
3737

3838
const permission = await getUserEntityPermissions(userId, 'workspace', workspaceId)
3939
if (permission !== 'admin' && permission !== 'write') {
@@ -56,7 +56,6 @@ export const POST = withRouteHandler(
5656
key,
5757
originalName: name,
5858
contentType,
59-
size,
6059
})
6160

6261
if (created) {

apps/sim/app/api/workspaces/[id]/files/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
listWorkspaceFiles,
1616
uploadWorkspaceFile,
1717
} from '@/lib/uploads/contexts/workspace'
18-
import { MAX_WORKSPACE_FILE_SIZE } from '@/lib/uploads/shared/types'
18+
import { MAX_WORKSPACE_FORMDATA_FILE_SIZE } from '@/lib/uploads/shared/types'
1919
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
2020
import { verifyWorkspaceMembership } from '@/app/api/workflows/utils'
2121

@@ -130,10 +130,10 @@ export const POST = withRouteHandler(
130130

131131
const fileName = rawFile.name || 'untitled.md'
132132

133-
if (rawFile.size > MAX_WORKSPACE_FILE_SIZE) {
133+
if (rawFile.size > MAX_WORKSPACE_FORMDATA_FILE_SIZE) {
134134
return NextResponse.json(
135135
{
136-
error: `File size exceeds maximum of ${MAX_WORKSPACE_FILE_SIZE} bytes (${(rawFile.size / (1024 * 1024)).toFixed(2)}MB)`,
136+
error: `File size exceeds maximum of ${MAX_WORKSPACE_FORMDATA_FILE_SIZE} bytes (${(rawFile.size / (1024 * 1024)).toFixed(2)}MB)`,
137137
},
138138
{ status: 413 }
139139
)

apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,8 @@ export async function registerUploadedWorkspaceFile(params: {
290290
key: string
291291
originalName: string
292292
contentType: string
293-
/** Caller-supplied size; verified against storage HEAD when cloud storage is configured. */
294-
size: number
295293
}): Promise<RegisterUploadedWorkspaceFileResult> {
296-
const { workspaceId, userId, key, originalName, contentType, size } = params
294+
const { workspaceId, userId, key, originalName, contentType } = params
297295

298296
if (!hasCloudStorage()) {
299297
throw new Error('Direct-upload registration requires cloud storage')

apps/sim/lib/uploads/shared/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
*/
66
export const MAX_WORKSPACE_FILE_SIZE = 5 * 1024 * 1024 * 1024
77

8+
/**
9+
* Cap on the legacy FormData upload route, which buffers the whole file in
10+
* worker memory. Direct-to-storage uploads use {@link MAX_WORKSPACE_FILE_SIZE}.
11+
*/
12+
export const MAX_WORKSPACE_FORMDATA_FILE_SIZE = 100 * 1024 * 1024
13+
814
export type StorageContext =
915
| 'knowledge-base'
1016
| 'chat'

0 commit comments

Comments
 (0)