Мне нужна помощь с использованием API aspose.omr. Я создал шаблон, но не могу его распознать.
Когда я вызываю /v5.1/omr/RecounceeTemplate/PostRecounceeTemplate
и передаю файл OMR как Base64, а лист ответов как Base64, я получаю ответ об ошибке.
Мой код:
Мне нужна помощь с использованием API aspose.omr. Я создал шаблон, но не могу его распознать. Когда я вызываю /v5.1/omr/RecounceeTemplate/PostRecounceeTemplate и передаю файл OMR как Base64, а лист ответов как Base64, я получаю ответ об ошибке. Мой код: [code]public async Task RecognizeTemplateAsync(string accessToken, string filledTemplateImageBase64, string omrFileBase64, string outputFormat, int recognitionThreshold) { // Create the multipart form data content var formData = new MultipartFormDataContent();
// Add the filled template image (Base64-encoded) var imageContent = new StringContent(filledTemplateImageBase64, Encoding.UTF8, "text/plain"); formData.Add(imageContent, "Images");
// Add the OMR template file (Base64-encoded) var omrFileContent = new StringContent(omrFileBase64, Encoding.UTF8, "text/plain"); formData.Add(omrFileContent, "omrFile");
// Set headers _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
// Send request var response = await _httpClient.PostAsync("https://api.aspose.cloud/v5.1/omr/RecognizeTemplate/PostRecognizeTemplate", formData);
// Check for errors if (!response.IsSuccessStatusCode) { var errorResponse = await response.Content.ReadAsStringAsync(); throw new HttpRequestException($"Error recognizing template: {response.StatusCode}. Response: {errorResponse}"); }
// Read the response as JSON var responseData = await response.Content.ReadAsStringAsync(); return responseData; }
[HttpPost("RecognizeTemplate")] public async Task RecognizeTemplate( [FromForm] string Images, // List of Base64-encoded images [FromForm] string omrFile, // Base64-encoded OMR template file [FromForm] string outputFormat, // Output format (e.g., "CSV") [FromForm] int recognitionThreshold) // Recognition threshold (e.g., 35) { try { // Step 1: Validate inputs if (Images == null) { return BadRequest("At least one filled template image is required."); }
if (string.IsNullOrEmpty(omrFile)) { return BadRequest("OMR template file is required."); }
if (string.IsNullOrEmpty(outputFormat)) { return BadRequest("Output format is required."); }
// Step 2: Get Access Token var clientId = ""; var clientSecret = ""; var accessToken = await _accessTokenService.GetAccessTokenAsync(clientId, clientSecret);
// Step 3: Recognize the filled template var recognitionResult = await _omrService.RecognizeTemplateAsync( accessToken, Images, omrFile, outputFormat, recognitionThreshold);
// Step 4: Return the recognition result return Content(recognitionResult, "application/json"); } catch (Exception ex) { return StatusCode(500, $"Error recognizing template: {ex.Message}"); } } [/code] Ответ об ошибке: [code]{ "type": "https://tools.ietf.org/html/rfc7231#section-6.5.13", "title": "Unsupported Media Type", "status": 415, "traceId": "00-3416c993f09f7b5a4f53408ef0b8888e-a23775435dd324eb-00" } [/code] Как мне успешно распознать файл OMR?