mirror of
https://github.com/hanzoai/mcp-server-cloudflare.git
synced 2026-10-30 18:28:06 +00:00
20 lines
628 B
TypeScript
20 lines
628 B
TypeScript
export async function fileToBase64(blob: Blob): Promise<string> {
|
|
// Use ArrayBuffer instead of text() for binary data
|
|
const arrayBuffer = await blob.arrayBuffer()
|
|
const byteArray = new Uint8Array(arrayBuffer)
|
|
|
|
// Convert byte array to base64 string
|
|
let binary = ''
|
|
byteArray.forEach((byte) => {
|
|
binary += String.fromCharCode(byte)
|
|
})
|
|
|
|
// Apply base64 encoding
|
|
return btoa(binary)
|
|
}
|
|
|
|
// Used for file related tool calls in case the llm sends a full resource URI
|
|
export async function stripProtocolFromFilePath(path: string): Promise<string> {
|
|
return path.startsWith('file://') ? path.replace('file://', '') : path
|
|
}
|