MCPcopy
hub / github.com/iterative/cml / upload

Function upload

src/utils.js:77–99  ·  view source on GitHub ↗
(opts)

Source from the content-addressed store, hash-verified

75};
76
77const upload = async (opts) => {
78 const { path, session, url = 'https://asset.cml.dev' } = opts;
79
80 const { mime, size, data: body } = await fetchUploadData(opts);
81 const filename = path ? PATH.basename(path) : `file.${mime.split('/')[1]}`;
82
83 const headers = {
84 'Content-Length': size,
85 'Content-Type': mime,
86 'Content-Disposition': `inline; filename="${filename}"`
87 };
88
89 if (session) headers['Content-Address-Seed'] = `${session}:${path}`;
90 const response = await fetch(url, { method: 'POST', headers, body });
91 const uri = await response.text();
92
93 if (!uri)
94 throw new Error(
95 `Empty response from asset backend with status code ${response.status}`
96 );
97
98 return { uri, mime, size };
99};
100
101const randid = () => {
102 return (

Callers 2

utils.test.jsFile · 0.85
publishMethod · 0.85

Calls 1

fetchUploadDataFunction · 0.85

Tested by

no test coverage detected