MCPcopy
hub / github.com/cortexlabs/cortex / HTTPUpload

Function HTTPUpload

cli/cluster/lib_http_client.go:95–128  ·  view source on GitHub ↗
(operatorConfig OperatorConfig, endpoint string, input *HTTPUploadInput, qParams ...map[string]string)

Source from the content-addressed store, hash-verified

93}
94
95func HTTPUpload(operatorConfig OperatorConfig, endpoint string, input *HTTPUploadInput, qParams ...map[string]string) ([]byte, error) {
96 body := new(bytes.Buffer)
97 writer := multipart.NewWriter(body)
98
99 for fileName, filePath := range input.FilePaths {
100 file, err := files.Open(filePath)
101 if err != nil {
102 return nil, err
103 }
104
105 defer file.Close()
106 if err := addFileToMultipart(fileName, writer, file); err != nil {
107 return nil, err
108 }
109 }
110
111 for fileName, fileBytes := range input.Bytes {
112 if err := addFileToMultipart(fileName, writer, bytes.NewReader(fileBytes)); err != nil {
113 return nil, err
114 }
115 }
116
117 if err := writer.Close(); err != nil {
118 return nil, errors.Wrap(err, _errStrCantMakeRequest)
119 }
120
121 req, err := operatorRequest(operatorConfig, http.MethodPost, endpoint, body, qParams...)
122 if err != nil {
123 return nil, err
124 }
125
126 req.Header.Set("Content-Type", writer.FormDataContentType())
127 return makeOperatorRequest(operatorConfig, req)
128}
129
130func addFileToMultipart(fileName string, writer *multipart.Writer, reader io.Reader) error {
131 part, err := writer.CreateFormFile(fileName, fileName)

Callers 2

HTTPUploadZipFunction · 0.85
DeployFunction · 0.85

Calls 6

OpenFunction · 0.92
WrapFunction · 0.92
addFileToMultipartFunction · 0.85
operatorRequestFunction · 0.85
makeOperatorRequestFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected