Skip to content

Commit bd5866e

Browse files
committed
fix dropbox upload file
1 parent cfc3604 commit bd5866e

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

apps/sim/lib/core/utils/user-file.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,20 @@ export function filterUserFileForDisplay(data: Record<string, unknown>): Record<
5555
}
5656
return filtered
5757
}
58+
59+
/**
60+
* Extracts base64 content from either a raw base64 string or a UserFile object.
61+
* Useful for tools that accept file input in either format.
62+
* @returns The base64 string, or undefined if not found
63+
*/
64+
export function extractBase64FromFileInput(
65+
input: string | UserFileLike | null | undefined
66+
): string | undefined {
67+
if (typeof input === 'string') {
68+
return input
69+
}
70+
if (input?.base64) {
71+
return input.base64
72+
}
73+
return undefined
74+
}

apps/sim/tools/dropbox/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { UserFileLike } from '@/lib/core/utils/user-file'
12
import type { ToolFileData, ToolResponse } from '@/tools/types'
23

34
// ===== Core Types =====
@@ -70,7 +71,7 @@ export interface DropboxBaseParams {
7071

7172
export interface DropboxUploadParams extends DropboxBaseParams {
7273
path: string
73-
fileContent: string // Base64 encoded file content
74+
fileContent: string | UserFileLike
7475
fileName?: string
7576
mode?: 'add' | 'overwrite'
7677
autorename?: boolean

apps/sim/tools/dropbox/upload.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { extractBase64FromFileInput } from '@/lib/core/utils/user-file'
12
import type { DropboxUploadParams, DropboxUploadResponse } from '@/tools/dropbox/types'
23
import type { ToolConfig } from '@/tools/types'
34

@@ -31,10 +32,10 @@ export const dropboxUploadTool: ToolConfig<DropboxUploadParams, DropboxUploadRes
3132
'The path in Dropbox where the file should be saved (e.g., /folder/document.pdf)',
3233
},
3334
fileContent: {
34-
type: 'string',
35+
type: 'json',
3536
required: true,
3637
visibility: 'user-or-llm',
37-
description: 'The base64 encoded content of the file to upload',
38+
description: 'The file to upload (UserFile object or base64 string)',
3839
},
3940
fileName: {
4041
type: 'string',
@@ -84,8 +85,12 @@ export const dropboxUploadTool: ToolConfig<DropboxUploadParams, DropboxUploadRes
8485
}
8586
},
8687
body: (params) => {
88+
const base64Content = extractBase64FromFileInput(params.fileContent)
89+
if (!base64Content) {
90+
throw new Error('File Content cannot be extracted')
91+
}
8792
// Decode base64 to raw binary bytes - Dropbox expects raw binary, not base64 text
88-
return Buffer.from(params.fileContent, 'base64')
93+
return Buffer.from(base64Content, 'base64')
8994
},
9095
},
9196

0 commit comments

Comments
 (0)