Skip to content

Commit

Permalink
Multipart without form breakage (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeCooper authored Nov 13, 2020
1 parent 8e294c3 commit fef5284
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions gateway/up.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
package gateway

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"mime/multipart"
"net/http"

"github.com/railwayapp/cli/entity"
)

func constructReq(ctx context.Context, req *entity.UpRequest) (*http.Request, error) {
body := new(bytes.Buffer)
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("file", req.ProjectID)
url := fmt.Sprintf("%s/project/%s/environment/%s/up", GetHost(), req.ProjectID, req.EnvironmentID)
httpReq, err := http.NewRequest("POST", url, &req.Data)
if err != nil {
return nil, err
}
part.Write(req.Data.Bytes())

err = writer.Close()
if err != nil {
return nil, err
}
url := fmt.Sprintf("%s/project/%s/up", GetHost(), req.ProjectID)
httpReq, err := http.NewRequest("POST", url, body)
if err != nil {
return nil, err
}
httpReq.Header.Set("Content-Type", writer.FormDataContentType())
httpReq.Header.Set("Content-Type", "multipart/form-data")
return httpReq, nil
}

Expand Down

0 comments on commit fef5284

Please sign in to comment.