Skip to content

Commit 26b188e

Browse files
committed
chore(LTV3): Include filename for translate doc
1 parent 1df9e7f commit 26b188e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

ibm_watson/language_translator_v3.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ def list_documents(self, **kwargs):
479479

480480
def translate_document(self,
481481
file,
482+
filename=None,
482483
file_content_type=None,
483484
model_id=None,
484485
source=None,
@@ -496,6 +497,7 @@ def translate_document(self,
496497
[Supported file
497498
types](https://cloud.ibm.com/docs/services/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats)
498499
Maximum file size: **20 MB**.
500+
:param str filename: The filename for file.
499501
:param str file_content_type: The content type of file.
500502
:param str model_id: The model to use for translation. `model_id` or both `source`
501503
and `target` are required.
@@ -523,7 +525,11 @@ def translate_document(self,
523525
params = {'version': self.version}
524526

525527
form_data = {}
526-
form_data['file'] = (None, file, file_content_type or
528+
if not filename and hasattr(file, 'name'):
529+
filename = basename(file.name)
530+
if not filename:
531+
raise ValueError('filename must be provided')
532+
form_data['file'] = (filename, file, file_content_type or
527533
'application/octet-stream')
528534
if model_id:
529535
form_data['model_id'] = (None, model_id, 'text/plain')

0 commit comments

Comments
 (0)