support base64\url
(imgFile string)
| 168 | |
| 169 | // support base64\url |
| 170 | func 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 | |
| 202 | func getSignedUpload() (*FileUploadResult, *WrapperErrorResp) { |
| 203 | url := common.BaseUrl + FileUploadEndpoint + "?file_type=image&filename=file.jpg" |
no test coverage detected