Jaycean commented on a change in pull request #1465:
URL: https://github.com/apache/apisix-dashboard/pull/1465#discussion_r580827765



##########
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:
       @liuxiran 
   
   Because the front-end has cross-domain problems, it needs to conduct a 
transparent transmission through the manage API. 
   
   Here, the front-end places the file bytes in the body and transfers them to 
the back-end, and then directly transmits them through the back-end. Therefore, 
the E2E test needs to read the file here.




----------------------------------------------------------------
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


Reply via email to