(ctx context.Context, uploadURL string, reader io.Reader, contentType string)
| 82 | } |
| 83 | |
| 84 | func UploadReaderWithContentType(ctx context.Context, uploadURL string, reader io.Reader, contentType string) error { |
| 85 | req, err := http.NewRequestWithContext(ctx, http.MethodPut, uploadURL, reader) |
| 86 | if err != nil { |
| 87 | return fmt.Errorf("failed to create request: %w", err) |
| 88 | } |
| 89 | req.Header.Set("Content-Type", contentType) |
| 90 | |
| 91 | resp, err := http.DefaultClient.Do(req) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | defer resp.Body.Close() |
| 96 | if resp.StatusCode != http.StatusOK { |
| 97 | body, readErr := io.ReadAll(resp.Body) |
| 98 | if readErr != nil { |
| 99 | return fmt.Errorf("failed to read response body: %w", readErr) |
| 100 | } |
| 101 | return fmt.Errorf("status %s: %s", resp.Status, body) |
| 102 | } |
| 103 | return nil |
| 104 | } |
| 105 | |
| 106 | func NormalizeContent(s string) string { |
| 107 | s = strings.TrimSpace(s) |
no test coverage detected