Download fetches a file by uploaded hash, but it forces format conversion.
(ctx context.Context, id uuid.UUID, format string)
| 46 | |
| 47 | // Download fetches a file by uploaded hash, but it forces format conversion. |
| 48 | func (c *Client) DownloadWithFormat(ctx context.Context, id uuid.UUID, format string) ([]byte, string, error) { |
| 49 | res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/files/%s?format=%s", id.String(), format), nil) |
| 50 | if err != nil { |
| 51 | return nil, "", err |
| 52 | } |
| 53 | defer res.Body.Close() |
| 54 | if res.StatusCode != http.StatusOK { |
| 55 | return nil, "", ReadBodyAsError(res) |
| 56 | } |
| 57 | data, err := io.ReadAll(res.Body) |
| 58 | if err != nil { |
| 59 | return nil, "", err |
| 60 | } |
| 61 | return data, res.Header.Get("Content-Type"), nil |
| 62 | } |