MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / multipartFetch

Function multipartFetch

native.ts:71–82  ·  view source on GitHub ↗
(url: string, fields: Record<string, string>, fileFieldName: string, fileBuffer: ArrayBuffer, filename: string, headers: Record<string, string> = {})

Source from the content-addressed store, hash-verified

69}
70
71function multipartFetch(url: string, fields: Record<string, string>, fileFieldName: string, fileBuffer: ArrayBuffer, filename: string, headers: Record<string, string> = {}): Promise<Response> {
72 const boundary = `----BigFileUpload${Date.now().toString(16)}${Math.random().toString(16).slice(2)}`;
73 const encoder = new TextEncoder();
74 const safeName = filename.replace(/[\r\n"]/g, "_");
75 let head = "";
76 for (const [name, value] of Object.entries(fields)) {
77 head += `--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`;
78 }
79 head += `--${boundary}\r\nContent-Disposition: form-data; name="${fileFieldName}"; filename="${safeName}"\r\nContent-Type: application/octet-stream\r\n\r\n`;
80 const parts = [encoder.encode(head), new Uint8Array(fileBuffer), encoder.encode(`\r\n--${boundary}--\r\n`)];
81 return streamFetch(url, "POST", headers, parts, `multipart/form-data; boundary=${boundary}`);
82}
83
84function rawFetch(url: string, method: string, fileBuffer: ArrayBuffer, headers: Record<string, string> = {}): Promise<Response> {
85 return streamFetch(url, method, headers, [new Uint8Array(fileBuffer)]);

Callers 10

uploadToNestFunction · 0.85
uploadToEzHostFunction · 0.85
uploadTo0x0Function · 0.85
uploadToCatboxFunction · 0.85
uploadToLitterboxFunction · 0.85
uploadToGofileFunction · 0.85
uploadToTmpfilesFunction · 0.85
uploadToTempShFunction · 0.85
uploadToFilebinFunction · 0.85
uploadToPixelVaultFunction · 0.85

Calls 1

streamFetchFunction · 0.85

Tested by

no test coverage detected