fix dropbox upload file

This commit is contained in:
Vikhyath Mondreti
2026-02-03 15:35:15 -08:00
parent cfc360404a
commit bd5866ed6b
3 changed files with 27 additions and 4 deletions

View File

@@ -55,3 +55,20 @@ export function filterUserFileForDisplay(data: Record<string, unknown>): Record<
}
return filtered
}
/**
* Extracts base64 content from either a raw base64 string or a UserFile object.
* Useful for tools that accept file input in either format.
* @returns The base64 string, or undefined if not found
*/
export function extractBase64FromFileInput(
input: string | UserFileLike | null | undefined
): string | undefined {
if (typeof input === 'string') {
return input
}
if (input?.base64) {
return input.base64
}
return undefined
}

View File

@@ -1,3 +1,4 @@
import type { UserFileLike } from '@/lib/core/utils/user-file'
import type { ToolFileData, ToolResponse } from '@/tools/types'
// ===== Core Types =====
@@ -70,7 +71,7 @@ export interface DropboxBaseParams {
export interface DropboxUploadParams extends DropboxBaseParams {
path: string
fileContent: string // Base64 encoded file content
fileContent: string | UserFileLike
fileName?: string
mode?: 'add' | 'overwrite'
autorename?: boolean

View File

@@ -1,3 +1,4 @@
import { extractBase64FromFileInput } from '@/lib/core/utils/user-file'
import type { DropboxUploadParams, DropboxUploadResponse } from '@/tools/dropbox/types'
import type { ToolConfig } from '@/tools/types'
@@ -31,10 +32,10 @@ export const dropboxUploadTool: ToolConfig<DropboxUploadParams, DropboxUploadRes
'The path in Dropbox where the file should be saved (e.g., /folder/document.pdf)',
},
fileContent: {
type: 'string',
type: 'json',
required: true,
visibility: 'user-or-llm',
description: 'The base64 encoded content of the file to upload',
description: 'The file to upload (UserFile object or base64 string)',
},
fileName: {
type: 'string',
@@ -84,8 +85,12 @@ export const dropboxUploadTool: ToolConfig<DropboxUploadParams, DropboxUploadRes
}
},
body: (params) => {
const base64Content = extractBase64FromFileInput(params.fileContent)
if (!base64Content) {
throw new Error('File Content cannot be extracted')
}
// Decode base64 to raw binary bytes - Dropbox expects raw binary, not base64 text
return Buffer.from(params.fileContent, 'base64')
return Buffer.from(base64Content, 'base64')
},
},