MCPcopy Create free account
hub / github.com/GetStream/stream-js / addFileToFormData

Function addFileToFormData

src/utils.ts:72–88  ·  view source on GitHub ↗
(uri: string | File | Buffer | NodeJS.ReadStream, name?: string, contentType?: string)

Source from the content-addressed store, hash-verified

70}
71
72function addFileToFormData(uri: string | File | Buffer | NodeJS.ReadStream, name?: string, contentType?: string) {
73 const data = new FormData();
74
75 if (isReadableStream(uri) || isBuffer(uri) || isFileWebAPI(uri)) {
76 if (name) data.append('file', uri, name);
77 else data.append('file', uri);
78 } else {
79 data.append('file', {
80 uri,
81 name: name || (uri as string).split('/').reverse()[0],
82 type: contentType || undefined,
83 contentType: contentType || undefined,
84 });
85 }
86
87 return data;
88}
89
90// TODO: refactor and add proper types
91function replaceStreamObjects<T, V>(obj: T): V {

Callers 1

client_test.jsFile · 0.85

Calls 3

isReadableStreamFunction · 0.85
isBufferFunction · 0.85
isFileWebAPIFunction · 0.85

Tested by

no test coverage detected