DeepL API: "Failed to open the uploaded document" Error When Translating XLIFF File
Closed this issue · 5 comments
Describe the bug
Describe the bug When attempting to translate an XLIFF file using the DeepL API with the provided code, the process fails, returning the error message:
{"document_id":"943F2A850142C982DB783AFB069BC892","status":"error","error_message":"Failed to open the uploaded document.","message":"Failed to open the uploaded document."}
To Reproduce
Steps to reproduce the behavior:
- Prepare an XLIFF file (input.xlf) with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.1" version="2.1" srcLang="en" trgLang="es">
<file id="f1" original="example.html">
<unit id="u1">
<segment id="s1">
<source>Hello, world!</source>
</segment>
</unit>
</file>
</xliff>
- Use the following Node.js code to initiate the translation:
import * as deepl from 'deepl-node';
import fs from 'fs';
const authKey = 'your-auth-key';
const translator = new deepl.Translator(authKey);
async function translateXLF() {
const inputFile = 'input.xlf';
const outputFile = 'output.xlf';
try {
await translator.translateDocument(
inputFile,
outputFile,
'en',
'es',
{
formality: 'default',
}
);
console.log('Translation completed successfully.');
} catch (error) {
if (error.documentHandle) {
console.error(`Document ID: ${error.documentHandle.documentId}, Document key: ${error.documentHandle.documentKey}`);
} else {
console.error(`Error occurred during document translation: ${error.message}`);
}
}
}
translateXLF();
3. Execute the script.
node index.js
- Observe the error message in the console output.
Request to DeepL API POST /v2/document
Request details: target_lang=es&source_lang=en&formality=default
DeepL API response POST /v2/document 200
Response details:, content = {"document_id":"XXX","document_key":"YYY"}
Request to DeepL API POST /v2/document/XXX
Request details: document_key=YYY
DeepL API response POST /v2/document/XXX 200
Response details:, content = {"document_id":"XXX","status":"error","error_message":"Failed to open the uploaded document.","message":"Failed to open the uploaded document."}
Desktop (please complete the following information):
- OS: Windows 11
- Browser Not applicable
- Version: Node.js 22.3.0
Additional context
The error message "Failed to open the uploaded document" suggests that the DeepL API is unable to process the provided XLIFF file. Using the same script i'm able to translate .docx and .txt files by replacing the input file.
I have the same problem, can't translate any xliff/xlf file but with postman😔
Sorry for only seeing this now. I can reproduce this and will check with the relevant team.
It seems your file is not valid according to the spec (see for example this example file ). A valid file would be
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.1" srcLang="en" trgLang="es">
<file id="f1" original="example.html">
<unit id="u1">
<segment id="s1">
<source>Hello, world!</source>
</segment>
</unit>
</file>
</xliff>
(Apparently XLIFF 2.1 still uses urn:oasis:names:tc:xliff:document:2.0). With this I get
<?xml version="1.0" encoding="utf-8"?><xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.1" srcLang="en" trgLang="es"><file id="f1" original="example.html"><unit id="u1"><segment id="s1"><source>Hello, world!</source><target>¡Hola, mundo!</target></segment></unit></file></xliff>
@marsee339 does this solve your issue too? Then I would close here
@JanEbbing yeah, thanks a lot! Such an unobvious mistake(