MCPcopy Index your code
hub / github.com/LumaAI-API/Luma-API / uploadFile

Function uploadFile

luma.go:170–200  ·  view source on GitHub ↗

support base64\url

(imgFile string)

Source from the content-addressed store, hash-verified

168
169// support base64\url
170func uploadFile(imgFile string) (*FileUploadResult, *WrapperErrorResp) {
171 signedUpload, relayErr := getSignedUpload()
172 if relayErr != nil {
173 return nil, relayErr
174 }
175
176 presignedURL := signedUpload.PresignedUrl
177
178 file, err := readImage(imgFile)
179 if err != nil {
180 return nil, GenLumaError(err, http.StatusInternalServerError)
181 }
182
183 resp, err := DoRequest(http.MethodPut, presignedURL, file, map[string]string{
184 "Content-Type": "image/*",
185 })
186 if err != nil {
187 return nil, GenLumaError(err, http.StatusInternalServerError)
188 }
189
190 defer resp.Body.Close()
191
192 if resp.StatusCode == http.StatusOK {
193 return signedUpload, nil
194 }
195 body, err := io.ReadAll(resp.Body)
196 if err != nil {
197 return nil, GenLumaError(err, http.StatusInternalServerError)
198 }
199 return nil, GenLumaError(fmt.Errorf(string(body)), resp.StatusCode)
200}
201
202func getSignedUpload() (*FileUploadResult, *WrapperErrorResp) {
203 url := common.BaseUrl + FileUploadEndpoint + "?file_type=image&filename=file.jpg"

Callers 2

UploadFunction · 0.85
doGenerationFunction · 0.85

Calls 4

getSignedUploadFunction · 0.85
readImageFunction · 0.85
GenLumaErrorFunction · 0.85
DoRequestFunction · 0.85

Tested by

no test coverage detected