Skip to content

Drive files create --upload ignores mimeType conversion (can't import HTML/docx as Google Docs) #719

@tofagerl

Description

@tofagerl

Bug Description

When uploading a file via gws drive files create --upload with mimeType: "application/vnd.google-apps.document" in --params, the file is uploaded as-is rather than being converted to a native Google Doc.

The Google Drive API supports importing files by setting mimeType in the metadata to the target Google Workspace type (e.g., application/vnd.google-apps.document) while sending the file content with its actual MIME type (e.g., text/html or application/vnd.openxmlformats-officedocument.wordprocessingml.document). This requires a multipart upload where metadata and file content are sent as separate parts.

The CLI appears to do a simple media upload, so the metadata mimeType is either ignored or used as the upload content type — neither of which triggers Drive's conversion.

Steps to Reproduce

# Convert markdown to HTML (or docx via pandoc)
echo "<h1>Hello</h1><p>World</p>" > /tmp/test.html

# Attempt to upload as a Google Doc
gws drive files create \
  --params '{"name":"Test Import","mimeType":"application/vnd.google-apps.document"}' \
  --upload /tmp/test.html

# Result: file is uploaded as text/html, NOT converted to a Google Doc
# Response shows: "mimeType": "text/html"
# Expected: "mimeType": "application/vnd.google-apps.document"

Same behavior with docx files — they upload as raw application/vnd.openxmlformats... instead of being converted.

Expected Behavior

When mimeType in --params is a Google Workspace type (application/vnd.google-apps.document, application/vnd.google-apps.spreadsheet, etc.) and --upload is provided, the CLI should:

  1. Use the --params mimeType as the metadata mimeType (target format)
  2. Detect the upload file's actual MIME type (from extension or content) for the media part
  3. Perform a multipart upload so Drive converts the file

Workaround

Upload the file via Google Drive web UI, then right-click > "Open with Google Docs" to trigger conversion manually.

Related Issues

Environment

  • gws version: 0.7.0
  • OS: macOS (Darwin, aarch64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions