Skip to content

Bug: FormData is empty and request fails with HTTP 412 in v3 when using SetFiles()Β #1046

@liyuan1125

Description

@liyuan1125

πŸ› Bug: FormData is empty and request fails with HTTP 412 in v3 when using SetFiles()

πŸ” Versions Tested
β€’ Resty v2 (latest stable): βœ… Works
β€’ Resty v3.0.0-beta.4: ❌ Fails with 412 Precondition Failed

package main

import (
	"fmt"
	"github.com/go-resty/resty/v2" // or v3
)

func main() {
	client := resty.New()

	addr := "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=xxx"

	resp, err := client.R().
		SetFiles(map[string]string{
			"media": "./media.jpg",
		}).
		Post(addr)

	if err != nil {
		fmt.Println("error:", err)
		return
	}

	fmt.Println("formData:", resp.Request.FormData)
	fmt.Println("statusCode", resp.StatusCode())
}

βœ… Output (v2):
formData: map[@media:[./media.jpg]]
statusCode: 200

❌ Output (v3.0.0-beta.3)
formData: map[]
statusCode: 412

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions