Upload word and excel file to Google File Search

,

Hi, I’m using Google File Search and overall it works quite well. However, I’m running into an issue when trying to upload Word and Excel files.

According to your documentation (referenced here: https://ai.google.dev/gemini-api/docs/file-search#supported-files), .doc, .docx, .xls, and .xlsx should be supported. But when I try to upload them, I get errors like:

Error uploading 'Viet/15. pham vi cung cap (ok).doc': Unknown mime type: Could not determine the mimetype for your file
please set the `mime_type` argument

Error uploading 'Viet/15. pham vi cung cap (ok).doc': 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': "* UploadToFileSearchStoreRequest.mime_type: When provided, MIME type must be in a valid type/subtype format (e.g., 'text/plain', 'application/pdf').\n", 'status': 'INVALID_ARGUMENT'}}

I also tried omitting the mime_type field, but it still fails with the same error.

Could you clarify the correct MIME types for Word and Excel uploads, or confirm whether the documentation is accurate regarding support for these formats? Additionally, is there any known workaround to make these uploads succeed?

Thanks!

Hi @quanlt Welcome to the forum!!!
Please set the mime_type parameter manually when uploading .doc and .xls files, as the automatic detection often fails to identify them correctly. Use the exact valueapplication/msword for .doc and application/vnd.ms-excel for .xls uploads. Thanks.

Hi, Thank for your reply, I set mime type but it doesn’t work @Nireeksha_K_A

# Create the File Search store with an optional display name
file_search_store = client.file_search_stores.create(config={'display_name': 'contract'})

# Upload the file into the File Search store
operation = client.file_search_stores.upload_to_file_search_store(
  file='contract.doc',
  file_search_store_name=file_search_store.name,
  config={
      'display_name' : 'contract.doc',
      'mime_type':'application/msword'
  }
)
google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': "* UploadToFileSearchStoreRequest.mime_type: When provided, MIME type must be in a valid type/subtype format (e.g., 'text/plain', 'application/pdf').\n", 'status': 'INVALID_ARGUMENT'}}

I am using google-genai version 1.52.0

uv pip show google-genai

Name: google-genai
Version: 1.52.0
Location: /Users/nhung/SilverAI/filesearch/.venv/lib/python3.12/site-packages
Requires: anyio, google-auth, httpx, pydantic, requests, tenacity, typing-extensions, websockets
Required-by:

I’ve encountered the same issue with .xlsx files when using upload_to_file_search_store().

I created a Proof of Concept to demonstrate the issue:

Key findings:

Step 1 (Direct upload with MIME type): :cross_mark: FAILS

client.file_search_stores.upload_to_file_search_store(
    file=f,
    file_search_store_name=store_name,
    config={
        'mime_type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    }
)

Error: 400 INVALID_ARGUMENT: When provided, MIME type must be in a valid type/subtype format

The MIME type IS valid and IANA-registered, but the API incorrectly rejects it.

Step 2 (Direct upload without MIME type): :cross_mark: FAILS
Error: Unknown mime type: Could not determine the mimetype for your file

Step 3 (File API + import): :white_check_mark: WORKS

# Upload via File API
file_ref = client.files.upload(
    file=f,
    config=types.UploadFileConfig(
        mime_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    )
)

# Import into file search store
client.file_search_stores.import_file(
    file_search_store_name=store_name,
    file_name=file_ref.name
)

Workaround: Use the File API upload + import approach (Step 3) until this server-side validation issue is fixed.

Environment:

  • Package: google-genai==1.53.0
  • Python 3.13.3
1 Like

I tested this workaround and it still fails :
‘code’: 500, ‘message’: ‘Internal error encountered.’, ‘status’: ‘INTERNAL’
it’s the same situation as using the demo app in https://aistudio.google.com/u/4/apps/bundled/ask_the_manual?showAssistant=true&showCode=true - i updated the code to support xls/doc and it does the same.

if file_ext in [‘.ppt’, ‘.pptx’, ‘.doc’, ‘.docx’, ‘.xls’, ‘.xlsx’]:

                log.info(f"Using File API + import workaround for Office file: {file_ext}")

# Step 1: Upload via File API with explicit MIME type

with open(file_path, ‘rb’) as f:

                    file_ref = self.\_google_client.files.upload(

file=f,

config=types.UploadFileConfig(

mime_type=mime_type,

display_name=original_filename

                        )

                    )

                log.info(f"File uploaded to File API: {file_ref.name}")

# Wait for file to be processed

while file_ref.state.name == “PROCESSING”:

                    time.sleep(2)

                    file_ref = self.\_google_client.files.get(name=file_ref.name)

if file_ref.state.name == “FAILED”:

raise Exception(f"File processing failed: {file_ref.name}")

# Step 2: Import into file search store

                operation = self.\_google_client.file_search_stores.import_file(

file_search_store_name=self._file_search_store_name,

file_name=file_ref.name

                )

# Wait for import to complete

while not operation.done:

                    time.sleep(2)

                    operation = self.\_google_client.operations.get(operation)

                log.info(f"File imported to File Search Store successfully: {original_filename}")

return {

“status”: “success”,

“file_path”: file_path,

“google_file_search_store”: self._file_search_store_name,

“google_file_name”: file_ref.name

                }

Confirm, this flow works

1 Like