-
-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multipart file upload name parameter is not configurable #617
Comments
@TLINDEN Thanks for reaching out. I think I'm able to follow, still didn't get a full understanding. Could you please provide test case to demonstrate your use case/issue (client side and server side)? |
Yeah, this is (better: was, 'cause in the meantime I switched to another module) the client code: package lib
import (
"encoding/json"
"fmt"
"github.com/go-resty/resty/v2"
"os"
"path/filepath"
)
type Response struct {
Code int `json:"code"`
Success bool `json:"success"`
Message string `json:"message"`
}
func Runclient(cfg *cfg.Config, args []string) error {
client := resty.New()
client.SetDebug(cfg.Debug)
url := cfg.Endpoint + "/putfile"
files := os.Args[1:]
postfiles := make(map[string]string)
for _, file := range files {
postfiles[filepath.Base(file)] = file
}
resp, err := client.R().
SetFiles(postfiles).
SetFormData(map[string]string{"expire": "1d"}).
Post(url)
if cfg.Debug {
fmt.Println("Response Info:")
fmt.Println(" Error :", err)
fmt.Println(" Status Code:", resp.StatusCode())
fmt.Println(" Status :", resp.Status())
fmt.Println(" Proto :", resp.Proto())
fmt.Println(" Time :", resp.Time())
fmt.Println(" Received At:", resp.ReceivedAt())
fmt.Println(" Body :\n", resp)
fmt.Println()
}
r := Response{}
json.Unmarshal([]byte(resp.String()), &r)
fmt.Println(r)
} Serverside code is here |
@TLINDEN Thanks for sharing the code snippet. I will have a look and try to understand the context of the issue. |
this can help you : https://github.com/gospider007/requests/blob/master/test/request/file_test.go |
This has been handled in Resty v3 development, PR #879. It is currently available in the main branch. The following methods allow the same field name for multiple files.
The method |
If you upload multiple files resty sets the
name=
form-data parameter to the filename of each file, e.g. when uploading 2 files,xxx
andyyy
:The problem is, I am using GIN on the receiving end and want to fetch all the uploaded files, which is currently not possible because there's no array with a shared name parameter.
Here's how such a request should look if done right, using:
posted content:
It is possible to circumnavigate this issue by manually populating the form data using
SetMultipartFields
. But this is a tedious job, which resty already does very well- in fact that's one of the very reasons I'm trying to use it.So, a method to set this name to a unique array over all uploaded files is required, something like
SetFormDataName
which then must set this parameter and append[]
. At least this would help me a lot!The text was updated successfully, but these errors were encountered: