Reputation: 2972
I'd like to translate multi .pptx files. I'm trying to use Google translate API
My request json file is below.
{
"source_language_code": "ja",
"target_language_codes": ["en"],
"input_configs": {
"gcsSource": {
"inputUri": "gs://project_name/1.pptx"
},
"gcsSource": {
"inputUri": "gs://project_name/2.pptx"
}
},
"output_config": {
"gcsDestination": {
"outputUriPrefix": "gs://project_name/ja-en/"
}
}
}
I got this error, when I request translation API.
"description": "Invalid value at 'input_configs' (oneof), oneof field 'source' is already set. Cannot set 'gcsSource'"
Then I changed second gcsSource
to gcsSource1
{
"source_language_code": "ja",
"target_language_codes": ["en"],
"input_configs": {
"gcsSource": {
"inputUri": "gs://project_name/1.pptx"
},
"gcsSource1": {
"inputUri": "gs://project_name/2.pptx"
}
},
"output_config": {
"gcsDestination": {
"outputUriPrefix": "gs://project_name/ja-en/"
}
}
}
The result was below.
"description": "Invalid JSON payload received. Unknown name \"gcsSource1\" at 'input_configs': Cannot find field."
gcsSource1
was used 2 times in the document
How should I chagne request json file, for translate multi files by translation API?
Endpoint is this. "https://translation.googleapis.com/v3/projects/project_name/locations/us-central1:batchTranslateDocument"
Note
Single file translation works fine.
{
"source_language_code": "ja",
"target_language_codes": ["en"],
"input_configs": {
"gcsSource": {
"inputUri": "gs://project_name/1.pptx"
},
},
"output_config": {
"gcsDestination": {
"outputUriPrefix": "gs://project_name/ja-en/"
}
}
}
Upvotes: 0
Views: 702
Reputation: 812
The issue is with the curly braces used within input_configs
. Since you want to use multiple elements, input_configs should be an array. So you should switch the curly braces with square braces as follows:
"input_configs": [
{
"gcsSource": {
"inputUri": "gs://bucket_name/1.pptx"
}
},
{
"gcsSource": {
"inputUri": "gs://bucket_name/2.pptx"
}
}
]
Also, you cannot change the names of json keys, as the structure of request.json which will be passed to the endpoint should be as mentioned in the documentation. This is the reason that when you change the key to “gcsSource1”
, it gives you an error with “Cannot find field”.
Upvotes: 1