Bug: FormData is empty and request fails with HTTP 412 in v3 when using SetFiles()
Author: liyuan1125Created Jul 30, 2025Updated Aug 5, 2026
Labelsinteraction
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
Source: go-resty/resty