Skip to content

Commit 595d9ea

Browse files
committed
feat: add fix for file upload
1 parent ee536e4 commit 595d9ea

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

server/cmd/api/api/fs.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,17 @@ func (s *ApiService) UploadFiles(ctx context.Context, request oapi.UploadFilesRe
686686
}
687687
return idx, field, true
688688
}
689-
// forms like files.0.file
689+
// forms like files.0.file OR files.file (no index → index 0)
690690
if strings.HasPrefix(name, "files.") {
691691
parts := strings.Split(name, ".")
692+
if len(parts) == 2 {
693+
// comma/no-index format: files.dest_path or files.file
694+
field := parts[1]
695+
if field == "file" || field == "dest_path" {
696+
return 0, field, true
697+
}
698+
return 0, "", false
699+
}
692700
if len(parts) != 3 {
693701
return 0, "", false
694702
}

server/cmd/api/api/fs_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,33 @@ func TestUploadFilesMultipleAndOutOfOrder(t *testing.T) {
347347
}
348348
}
349349

350+
func TestUploadFilesCommaFormat(t *testing.T) {
351+
t.Parallel()
352+
ctx := context.Background()
353+
svc := &ApiService{}
354+
355+
tmp := t.TempDir()
356+
dest := filepath.Join(tmp, "comma.txt")
357+
358+
// SDK "comma" array format: files.dest_path, files.file (no index)
359+
reader := buildUploadMultipart(t,
360+
map[string]string{"files.dest_path": dest},
361+
map[string]string{"files.file": "hello comma"},
362+
)
363+
364+
resp, err := svc.UploadFiles(ctx, oapi.UploadFilesRequestObject{Body: reader})
365+
if err != nil {
366+
t.Fatalf("UploadFiles error: %v", err)
367+
}
368+
if _, ok := resp.(oapi.UploadFiles201Response); !ok {
369+
t.Fatalf("unexpected response type: %T", resp)
370+
}
371+
data, err := os.ReadFile(dest)
372+
if err != nil || string(data) != "hello comma" {
373+
t.Fatalf("uploaded file mismatch: %v %q", err, string(data))
374+
}
375+
}
376+
350377
func TestUploadZipSuccess(t *testing.T) {
351378
t.Parallel()
352379
ctx := context.Background()

0 commit comments

Comments
 (0)