Doctranslate.io Translation API
  • Introduction
    • Welcome to Doctranslate.io
    • What is DocTranslate.io
    • User Manual
  • Document Translation API
    • System requirement
    • Upload API
      • Upload multiple files and calculate usage cost
    • User API
      • User History
    • Translation API
      • API V1
        • Document Translation
        • Translate Multiple Files (currently supports document, video)
        • Image Translation
        • Audio Translation
        • Text Translation
        • Get result
      • API V2
        • Document Translation
        • Translate Multiple Files (currently supports document, video)
        • Image Translation
        • Audio Translation
        • Text Translation
        • Get result
      • API V3
        • Document Translation
        • Translate Multiple Files (currently supports document, video)
        • Audio Translation
        • Text Translation
        • Get result
    • Presentation Maker API
      • API V1
        • Presentation Maker
        • Presentation Maker For Multiple Files
      • API V2
        • Presentation Maker
        • Presentation Maker For Multiple Files
  • Presentation Video API
    • API V1
      • Create transcripts presentation
      • Update transcripts presentation
      • Create video presentation
      • Get result
    • API V2
      • Create transcripts presentation
      • Update transcripts presentation
      • Create video presentation
      • Get result
  • Others
    • Code examples
      • API V1
        • Upload Multiple Files
        • Translate Multiple Document Files
        • Text Translation
        • Document Translation
        • Image Translation
        • Audio Translation
        • Video Translation
        • Presentation Maker
        • Presentation Video
      • API V2
        • Upload Multiple Files
        • Translate Multiple Document Files
        • Text Translation
        • Document Translation
        • Image Translation
        • Audio Translation
        • Video Translation
        • Presentation Maker
        • Presentation Video
    • Support
Powered by GitBook
On this page
  1. Others
  2. Code examples
  3. API V1

Upload Multiple Files

import requests
import datetime
import time

# Authentication token
auth_token = "<YOUR_API_TOKEN>"

headers = {'Authorization': f'Bearer {auth_token}'}

# Constants for URLs and content type
BASE_URL = "https://doctranslate-api.doctranslate.io"
TRANSLATE_DOCUMENT_URL = f"{BASE_URL}/v1/process"
GET_RESULT_ENDPOINT = f"{BASE_URL}/v1/result/"
UPLOAD_FILE_URL = f"{BASE_URL}/v1/upload"

# File paths
input_file_path = ['/data/example.docx', '/data/example_2.docx']  # Input file path

# UPLOAD FILE PART
TASK_TYPE = 'document'

form_data = {
    'task_type': TASK_TYPE,
}

# add files to the form data
files = [('files', open(file_path, 'rb')) for file_path in input_file_paths]

meta_files = []
try:
    response = requests.post(UPLOAD_FILE_URL, data=form_data, files=files,
                             headers=headers)
    response.raise_for_status()  # Proper error handling

    response_data = response.json()
    meta_files = response_data.get('data', {})
    for metadata in meta_files:
        if metadata["task_id"]:
            print(f'Task ID: {metadata["task_id"]}')
        else:
            print('Failed to get the task ID from the response.')
except requests.exceptions.RequestException as e:
    print(f'An error occurred: {e}')
PreviousAPI V1NextTranslate Multiple Document Files

Last updated 11 months ago