(uri: string | File | Buffer | NodeJS.ReadStream, name?: string, contentType?: string)
| 70 | } |
| 71 | |
| 72 | function 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 |
| 91 | function replaceStreamObjects<T, V>(obj: T): V { |
no test coverage detected