Azure Document Translator is not working ,But getting response code is 202

66 Views Asked by At

I am trying to use the Azure Document Translation Service to translate a Document from English to Janapese. The hierarchy of the BLOB is given below.

|-storage account
|--container (test)
|---translation-input url (ex:https://storageaccount/test/sampleTranslation.docx)
|---translation-output url (ex:https://storageaccount/test/Converted_sampleTranslation.docx)

I am doing with httpclient using json input:

{
   "inputs":[
      {
         "storageType":"File",
         "source":{
            "sourceUrl":"https://storageaccount/test/sampleTranslation.docx?sp=racwl&st=24Z&se=2025-07-31T17:58:24Z&spr=https&sv=2020-08-04&sr=c&sig=xsd%3D%3D"
         },
         "targets":[
            {
               "targetUrl":"https://storageaccount/test/Converted_sampleTranslation.docx?sp=racwl&st=kjkZ&se=2025-07-31T17:58:24Z&spr=https&sv=2020-08-04&sr=c&sig=3LT7WCD5Tn7KK1JBTxaSOs%3D",
               "language":"ja"
            }
         ]
      }
   ]
}

Code snippet:

HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage();
{

    StringContent content = new StringContent(json, Encoding.UTF8, "application/json");

    request.Method = HttpMethod.Post;
    request.RequestUri = new Uri(endpoint + route);
    request.Headers.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
    request.Content = content;

    HttpResponseMessage response = await client.SendAsync(request);
    string result = response.Content.ReadAsStringAsync().Result;
    if (response.IsSuccessStatusCode)
    {

        outcome = "https://storageaccount.blob.core.windows.net/test/" + fname;
      
    }
    else
        log.Error("Error in Translate Document");

}

I am getting response status is 202 (means successful) but there is no translation happening with specified targeturl,

Note: Same code worked as expected in few months before. But today not getting expected result. what is the issue?

1

There are 1 best solutions below

0
Vivek Vaibhav Shandilya On

This worked for me.

  • I created two containers
  • For sourcefile : source with read &listaccess, for translated file: target with read,write&list access, I generated container level SAS.

My code:

using Azure.AI.Translation.Document;
using Azure;
using System;

namespace ConsoleApp3
{
    public class Program
    {
        public static async Task Main()
        {
            string endpoint = "https://doctranslation2703.cognitiveservices.azure.com/";
            string apiKey = "xxxxxxxxxxxxxxxx";
            var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

            Uri target = new Uri("https://translationstrgaccount.blob.core.windows.net/target?sp=rwl&st=2024-03-28T06:20:34Z&se=2024-03-30T14:20:34Z&spr=https&sv=2022-11-02&sr=c&sig=xxxxxxxxxxxxxxxxxx");
            Uri source = new Uri("https://translationstrgaccount.blob.core.windows.net/source?sp=rl&st=2024-03-28T06:19:34Z&se=2024-03-30T14:19:34Z&spr=https&sv=2022-11-02&sr=c&sig=xxxxxxxxxxxxxxxxxx");
                
            DocumentTranslationOperation operation = await client.StartTranslationAsync(new DocumentTranslationInput(sourceUri:source,targetUri: target,"ja"));

            await operation.WaitForCompletionAsync();

            Console.WriteLine($"Succeeded: {operation.DocumentsSucceeded}");

        }
    }
}

OUTPUT:

Hi! My name is Vivek

This is a English sentance.

it created a same name file in container with translated language.

過度の渇望!私の名前はヴィヴェックです

これは英語の文章です。