(projectId string, file stream.Stream, contentType string, uploadBar *visualization.ProgressBar)
| 31 | } |
| 32 | |
| 33 | func (c DuClient) StartDigitization(projectId string, file stream.Stream, contentType string, uploadBar *visualization.ProgressBar) (string, error) { |
| 34 | context, cancel := context.WithCancelCause(context.Background()) |
| 35 | request := c.createStartDigitizationRequest(projectId, file, contentType, uploadBar, cancel) |
| 36 | client := network.NewHttpClient(c.logger, c.httpClientSettings()) |
| 37 | response, err := client.SendWithContext(request, context) |
| 38 | if err != nil { |
| 39 | return "", err |
| 40 | } |
| 41 | defer func() { _ = response.Body.Close() }() |
| 42 | body, err := io.ReadAll(response.Body) |
| 43 | if err != nil { |
| 44 | return "", fmt.Errorf("Error reading response: %w", err) |
| 45 | } |
| 46 | if response.StatusCode != http.StatusAccepted { |
| 47 | return "", fmt.Errorf("Digitizer returned status code '%v' and body '%v'", response.StatusCode, string(body)) |
| 48 | } |
| 49 | var result digitizeResponse |
| 50 | err = json.Unmarshal(body, &result) |
| 51 | if err != nil { |
| 52 | return "", fmt.Errorf("Error parsing json response: %w", err) |
| 53 | } |
| 54 | return result.DocumentId, nil |
| 55 | } |
| 56 | |
| 57 | func (c DuClient) createStartDigitizationRequest(projectId string, file stream.Stream, contentType string, uploadBar *visualization.ProgressBar, cancel context.CancelCauseFunc) *network.HttpRequest { |
| 58 | streamSize, _ := file.Size() |
no test coverage detected