Jaycean commented on a change in pull request #1465: URL: https://github.com/apache/apisix-dashboard/pull/1465#discussion_r580799536
########## File path: api/test/e2enew/base/http.go ########## @@ -92,3 +104,44 @@ func BatchTestServerPort(times int) map[string]int { return res } + +func GetReader(reqParams map[string]string, contentType string, files []UploadFile) (io.Reader, string, error) { + if strings.Index(contentType, "json") > -1 { + bytesData, _ := json.Marshal(reqParams) + return bytes.NewReader(bytesData), contentType, nil + } + if files != nil { + body := &bytes.Buffer{} + writer := multipart.NewWriter(body) + for _, uploadFile := range files { + file, err := os.Open(uploadFile.Filepath) + if err != nil { + return nil, "", err + } + part, err := writer.CreateFormFile(uploadFile.Name, filepath.Base(uploadFile.Filepath)) + if err != nil { + return nil, "", err + } + _, err = io.Copy(part, file) + defer file.Close() + } + for k, v := range reqParams { + if err := writer.WriteField(k, v); err != nil { + return nil, "", err + } + } + if err := writer.Close(); err != nil { + return nil, "", err + } + return body, writer.FormDataContentType(), nil + } + + urlValues := url.Values{} + for key, val := range reqParams { + urlValues.Set(key, val) + } + + reqBody := urlValues.Encode() + + return strings.NewReader(reqBody), contentType, nil Review comment: Yes, because the sending file is added, the data type in the body is bytes. If it is put in the body, it is not convenient to read. So I communicated with @liuxiran at that time, so it can only put other parameters in the header. Do you have a better suggestion? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org