diff --git a/client.go b/client.go index 85fb149..145d19b 100644 --- a/client.go +++ b/client.go @@ -475,9 +475,9 @@ func (c *Client) FormData() url.Values { } // SetFormData method sets Form parameters and their values in the client instance. -// It applies only to HTTP methods `POST` and `PUT`, and the request content type would be set as -// `application/x-www-form-urlencoded`. These form data will be added to all the requests raised from -// this client instance. Also, it can be overridden at the request level. +// The request content type would be set as `application/x-www-form-urlencoded`. +// The client-level form data gets added to all the requests. Also, it can be +// overridden at the request level. // // See [Request.SetFormData]. // diff --git a/multipart.go b/multipart.go index 36eb88c..17cd6df 100644 --- a/multipart.go +++ b/multipart.go @@ -10,6 +10,7 @@ import ( "io" "net/textproto" "os" + "path/filepath" "strings" ) @@ -104,6 +105,10 @@ func (mf *MultipartField) openFileIfRequired() error { return err } + if isStringEmpty(mf.FileName) { + mf.FileName = filepath.Base(mf.FilePath) + } + // if file open is success, stat will succeed fileStat, _ := file.Stat() diff --git a/multipart_test.go b/multipart_test.go index f84a213..c69cb24 100644 --- a/multipart_test.go +++ b/multipart_test.go @@ -420,6 +420,11 @@ func TestMultipartFieldProgressCallback(t *testing.T) { } fields := []*MultipartField{ + { + Name: "test-image", + FilePath: filepath.Join(getTestDataPath(), "test-img.png"), + ProgressCallback: progressCallback, + }, { Name: "test-image-1", FileName: "test-image-1.png", @@ -456,6 +461,7 @@ func TestMultipartFieldProgressCallback(t *testing.T) { assertError(t, err) assertEqual(t, http.StatusOK, resp.StatusCode()) assertEqual(t, true, strings.Contains(responseStr, "test-image-1.png")) + assertEqual(t, true, strings.Contains(responseStr, "test-img.png")) assertEqual(t, true, strings.Contains(responseStr, "50mbfile.bin")) assertEqual(t, true, strings.Contains(responseStr, "100mbfile.bin")) } diff --git a/request.go b/request.go index 6336d12..5556752 100644 --- a/request.go +++ b/request.go @@ -297,9 +297,8 @@ func (r *Request) SetQueryString(query string) *Request { return r } -// SetFormData method sets Form parameters and their values for the current request. -// It applies only to HTTP methods `POST` and `PUT`, and by default requests -// content type would be set as `application/x-www-form-urlencoded`. +// SetFormData method sets form parameters and their values in the current request. +// The request content type would be set as `application/x-www-form-urlencoded`. // // client.R(). // SetFormData(map[string]string{