(formData, request3)
| 76181 | urlSearchParams.append(key, subValue.toString()); |
| 76182 | } |
| 76183 | } else { |
| 76184 | urlSearchParams.append(key, value.toString()); |
| 76185 | } |
| 76186 | } |
| 76187 | return urlSearchParams.toString(); |
| 76188 | } |
| 76189 | async function prepareFormData(formData, request3) { |
| 76190 | const contentType = request3.headers.get("Content-Type"); |
| 76191 | if (contentType && !contentType.startsWith("multipart/form-data")) { |
| 76192 | return; |
| 76193 | } |
| 76194 | request3.headers.set("Content-Type", contentType !== null && contentType !== void 0 ? contentType : "multipart/form-data"); |
| 76195 | const parts = []; |
| 76196 | for (const [fieldName, values] of Object.entries(formData)) { |
| 76197 | for (const value of Array.isArray(values) ? values : [values]) { |
| 76198 | if (typeof value === "string") { |
| 76199 | parts.push({ |
| 76200 | headers: createHttpHeaders({ |
| 76201 | "Content-Disposition": `form-data; name="${fieldName}"` |
| 76202 | }), |
| 76203 | body: stringToUint8Array(value, "utf-8") |
| 76204 | }); |
| 76205 | } else if (value === void 0 || value === null || typeof value !== "object") { |
| 76206 | throw new Error(`Unexpected value for key ${fieldName}: ${value}. Value should be serialized to string first.`); |
| 76207 | } else { |
| 76208 | const fileName = value.name || "blob"; |
| 76209 | const headers = createHttpHeaders(); |
| 76210 | headers.set("Content-Disposition", `form-data; name="${fieldName}"; filename="${fileName}"`); |
| 76211 | headers.set("Content-Type", value.type || "application/octet-stream"); |
| 76212 | parts.push({ |
| 76213 | headers, |
| 76214 | body: value |
| 76215 | }); |
| 76216 | } |
| 76217 | } |
no test coverage detected