diff --git a/client/withfilesoption.go b/client/withfilesoption.go index 6edde6e4ae6..eff0d1c25f3 100644 --- a/client/withfilesoption.go +++ b/client/withfilesoption.go @@ -91,7 +91,7 @@ func WithFiles() Option { for i, fileData := range filesGroup { mapDataFiles = append( mapDataFiles, - fmt.Sprintf(`"%d":[%s]`, i, strings.Join(collect(fileData, wrapMapKeyInQuotes)[:], ",")), + fmt.Sprintf(`"%d":[%s]`, i, strings.Join(collect(fileData, wrapMapKeyInQuotes), ",")), ) } @@ -105,10 +105,10 @@ func WithFiles() Option { // or // Content-Type: application/octet-stream // - for i, fileData := range filesData { + for i, fileData := range filesGroup { h := make(textproto.MIMEHeader) - h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%d"; filename="%s"`, i, fileData.file.Name())) - b, _ := ioutil.ReadFile(fileData.file.Name()) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%d"; filename="%s"`, i, fileData[0].file.Name())) + b, _ := ioutil.ReadFile(fileData[0].file.Name()) h.Set("Content-Type", http.DetectContentType(b)) ff, _ := bodyWriter.CreatePart(h) ff.Write(b) diff --git a/client/withfilesoption_test.go b/client/withfilesoption_test.go index c404a63629f..02f1a6a8677 100644 --- a/client/withfilesoption_test.go +++ b/client/withfilesoption_test.go @@ -209,6 +209,7 @@ func TestWithFiles(t *testing.T) { require.Equal(t, `text/plain; charset=utf-8`, p.Header.Get("Content-Type")) require.Equal(t, []byte(`hello world`), slurp) } + require.False(t, regexp.MustCompile(`form-data; name="2"; filename=.*`).MatchString(contentDisposition)) } w.Write([]byte(`{}`)) })