MCPcopy
hub / github.com/lightningpixel/modly / _multipart_form

Function _multipart_form

tools/modly-cli/agent.py:108–129  ·  view source on GitHub ↗
(fields: dict[str, str], file_field: str, file_path: Path)

Source from the content-addressed store, hash-verified

106
107
108def _multipart_form(fields: dict[str, str], file_field: str, file_path: Path) -> tuple[bytes, str]:
109 boundary = f"----modly-cli-{time.time_ns()}"
110 parts: list[bytes] = []
111
112 for name, value in fields.items():
113 parts.extend([
114 f"--{boundary}\r\n".encode(),
115 f'Content-Disposition: form-data; name="{name}"\r\n\r\n'.encode(),
116 str(value).encode("utf-8"),
117 b"\r\n",
118 ])
119
120 content_type = mimetypes.guess_type(file_path.name)[0] or "application/octet-stream"
121 parts.extend([
122 f"--{boundary}\r\n".encode(),
123 f'Content-Disposition: form-data; name="{file_field}"; filename="{file_path.name}"\r\n'.encode(),
124 f"Content-Type: {content_type}\r\n\r\n".encode(),
125 file_path.read_bytes(),
126 b"\r\n",
127 f"--{boundary}--\r\n".encode(),
128 ])
129 return b"".join(parts), f"multipart/form-data; boundary={boundary}"
130
131
132def _workspace_relative_path(output_url: str) -> str:

Callers 2

_start_workflow_runFunction · 0.85
_run_generation_jobFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected