Skip to content

Commit 0d41c2f

Browse files
committed
fix: use indexed bracket notation for multipart array encoding
Changes array encoding in addFormValue from `key + '[]'` to `key + '[' + i + ']'` so that arrays of objects produce indexed field names (e.g. files[0][dest_path]) instead of ambiguous empty-bracket names (e.g. files[][dest_path]). Without indices, the server cannot parse the field names (strconv.Atoi("") fails on the empty string between []) and cannot pair file contents with destination paths for multi-file uploads. Updates the existing form.test.ts assertion to expect the correct indexed format (bar[1] instead of bar[]). Made-with: Cursor
1 parent bb29258 commit 0d41c2f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/internal/uploads.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const addFormValue = async (form: FormData, key: string, value: unknown): Promis
174174
} else if (isNamedBlob(value)) {
175175
form.append(key, value, getName(value));
176176
} else if (Array.isArray(value)) {
177-
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
177+
await Promise.all(value.map((entry, i) => addFormValue(form, `${key}[${i}]`, entry)));
178178
} else if (typeof value === 'object') {
179179
// Special case: env_vars should always be flattened for backward compatibility
180180
// with APIs that expect env_vars[KEY] format

tests/form.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ describe('form data validation', () => {
122122
},
123123
fetch,
124124
);
125-
expect(Array.from(form2.entries())).toEqual([['bar[]', 'foo']]);
125+
expect(Array.from(form2.entries())).toEqual([['bar[1]', 'foo']]);
126126
});
127127
});

0 commit comments

Comments
 (0)