Skip to content

[Feishu] File upload fails with Chinese/special characters in filename #31179

@Liam777zzz

Description

@Liam777zzz

name: 🐛 Bug Report
about: Create a report to help us improve
title: "[Feishu] File upload fails with Chinese/special characters in filename"
labels: bug, feishu, file-upload

🐛 Bug Description

When sending files via Feishu channel with Chinese characters or special characters (e.g., em dash , spaces, brackets) in the filename, the file appears as a text link instead of a downloadable attachment. Users cannot download or preview the file.

🔄 Reproduction Steps

  1. Create a file with Chinese/special characters in filename:

    echo "test" > "测试文件—特殊字符(2026-03-02).md"
  2. Send via Feishu channel:

    openclaw message send \
      --target "ou_xxx" \
      --channel "feishu" \
      --filePath "/path/to/测试文件—特殊字符(2026-03-02).md"
  3. Observe in Feishu:

    • ❌ File appears as text link (underlined path)
    • ❌ Cannot download
    • ❌ Cannot preview

✅ Expected Behavior

File should be sent as a proper attachment with:

  • ✅ Downloadable file card
  • ✅ Preview support
  • ✅ Original filename preserved

📊 Actual Behavior

  • File sent as text link instead of attachment
  • Filename visible but not clickable
  • No download option available

🔍 Root Cause Analysis

The issue is in /extensions/feishu/src/media.tsuploadFileFeishu() function.

Current code (line ~213):

const response = await client.im.file.create({
  data: {
    file_type: fileType,
    file_name: fileName,  // ❌ Direct pass, no encoding
    file: fileData as any,
  },
});

Problem:

  • HTTP multipart/form-data follows RFC2388 which requires 7bit ASCII encoding for headers
  • Chinese characters and special characters (e.g., U+2014 em dash) exceed this range
  • Feishu API receives unencoded filename and treats it as text

Fix (tested and working):

// URL encode filename to handle Chinese characters and special characters
// RFC5987 encoding for multipart/form-data compatibility
const safeFileName = encodeURIComponent(fileName)
  .replace(/'/g, "%27")
  .replace(/\(/g, "%28")
  .replace(/\)/g, "%29");

const response = await client.im.file.create({
  data: {
    file_type: fileType,
    file_name: safeFileName,  // ✅ URL encoded
    file: fileData as any,
  },
});

🧪 Test Results

Test File Before Fix After Fix
上下文恢复系统 - 使用指南.md ❌ Text link ✅ File attachment
上下文恢复系统 - 原理详解.md ❌ Text link ✅ File attachment
测试文件—特殊字符(2026-03-02).md ❌ Text link ✅ File attachment

📋 Environment

  • OpenClaw Version: 2026.2.26
  • Node Version: 25.5.0
  • OS: Darwin 25.3.0 (arm64)
  • Channel: Feishu
  • Plugin: /extensions/feishu/src/media.ts

📎 Logs

[feishu] sendMediaFeishu failed: Error: Local file not found: /tmp/上下文恢复系统 - 使用指南.md
    at sendMediaFeishu (/Users/zane/.openclaw/extensions/feishu/src/media.ts:497:15)

💡 Suggested Fix

File: /extensions/feishu/src/media.ts
Function: uploadFileFeishu()
Line: ~210-215 (before client.im.file.create())

Add filename URL encoding:

// URL encode filename to handle Chinese characters and special characters
// RFC5987 encoding for multipart/form-data compatibility
const safeFileName = encodeURIComponent(fileName)
  .replace(/'/g, "%27")
  .replace(/\(/g, "%28")
  .replace(/\)/g, "%29");

🎯 Impact

  • Severity: High (blocks file sharing for non-English users)
  • Frequency: Every file with non-ASCII filename
  • Workaround: Manual filename sanitization (replace special characters)
  • Users Affected: All Feishu users with Chinese/special character filenames

📸 Screenshots

[Attach screenshots showing:

  1. File sent as text link (before fix)
  2. File sent as attachment (after fix)
  3. Download/preview working (after fix)
    ]

✅ Additional Context

  • This fix has been tested and verified working in production
  • Temporary workaround: Replace special characters with underscores
  • Permanent fix: Add URL encoding in uploadFileFeishu() function
  • Related: RFC2388 multipart/form-data encoding standards

Checklist:

  • I am using the latest OpenClaw version
  • I have searched the existing issues and this is a new bug
  • I have included reproduction steps
  • I have included expected vs actual behavior
  • I have included environment information
  • I have included logs
  • I have proposed a fix (optional)

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