MCPcopy Create free account
hub / github.com/different-ai/opencode-browser / buildFileUploadPayload

Function buildFileUploadPayload

src/plugin.ts:54–72  ·  view source on GitHub ↗
(
  filePath: string,
  fileName?: string,
  mimeType?: string
)

Source from the content-addressed store, hash-verified

52}
53
54function buildFileUploadPayload(
55 filePath: string,
56 fileName?: string,
57 mimeType?: string
58): { name: string; mimeType?: string; base64: string } {
59 const absPath = resolveUploadPath(filePath);
60 const stats = statSync(absPath);
61 if (!stats.isFile()) throw new Error(`Not a file: ${absPath}`);
62 if (stats.size > MAX_UPLOAD_BYTES) {
63 throw new Error(
64 `File too large (${stats.size} bytes). Max is ${MAX_UPLOAD_BYTES} bytes (OPENCODE_BROWSER_MAX_UPLOAD_BYTES). ` +
65 `For larger uploads, use OPENCODE_BROWSER_BACKEND=agent.`
66 );
67 }
68 const base64 = readFileSync(absPath).toString("base64");
69 const name = typeof fileName === "string" && fileName.trim() ? fileName.trim() : basename(absPath);
70 const mt = typeof mimeType === "string" && mimeType.trim() ? mimeType.trim() : undefined;
71 return { name, mimeType: mt, base64 };
72}
73
74type BrokerResponse =
75 | { type: "response"; id: number; ok: true; data: any }

Callers 1

executeFunction · 0.85

Calls 1

resolveUploadPathFunction · 0.85

Tested by

no test coverage detected