Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion server/cmd/api/api/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,17 @@ func (s *ApiService) UploadFiles(ctx context.Context, request oapi.UploadFilesRe
}
return idx, field, true
}
// forms like files.0.file
// forms like files.0.file OR files.file (no index → index 0)
if strings.HasPrefix(name, "files.") {
parts := strings.Split(name, ".")
if len(parts) == 2 {
// comma/no-index format: files.dest_path or files.file
field := parts[1]
if field == "file" || field == "dest_path" {
return 0, field, true
}
return 0, "", false
}
if len(parts) != 3 {
return 0, "", false
}
Expand Down
27 changes: 27 additions & 0 deletions server/cmd/api/api/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,33 @@ func TestUploadFilesMultipleAndOutOfOrder(t *testing.T) {
}
}

func TestUploadFilesCommaFormat(t *testing.T) {
t.Parallel()
ctx := context.Background()
svc := &ApiService{}

tmp := t.TempDir()
dest := filepath.Join(tmp, "comma.txt")

// SDK "comma" array format: files.dest_path, files.file (no index)
reader := buildUploadMultipart(t,
map[string]string{"files.dest_path": dest},
map[string]string{"files.file": "hello comma"},
)

resp, err := svc.UploadFiles(ctx, oapi.UploadFilesRequestObject{Body: reader})
if err != nil {
t.Fatalf("UploadFiles error: %v", err)
}
if _, ok := resp.(oapi.UploadFiles201Response); !ok {
t.Fatalf("unexpected response type: %T", resp)
}
data, err := os.ReadFile(dest)
if err != nil || string(data) != "hello comma" {
t.Fatalf("uploaded file mismatch: %v %q", err, string(data))
}
}

func TestUploadZipSuccess(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand Down
Loading