Skip to content

fix: pass ContentType to COS putObject and ensure charset=utf-8 for text uploads#138

Merged
yujiawei merged 3 commits intodmwork-org:mainfrom
Jerry-Xin:fix/cos-upload-content-type
Mar 30, 2026
Merged

fix: pass ContentType to COS putObject and ensure charset=utf-8 for text uploads#138
yujiawei merged 3 commits intodmwork-org:mainfrom
Jerry-Xin:fix/cos-upload-content-type

Conversation

@Jerry-Xin
Copy link
Copy Markdown
Collaborator

Summary

Bot file uploads to COS were missing the ContentType parameter in putObject, causing COS to default to application/octet-stream. This made text files (e.g. .md) download instead of displaying inline in the browser, and text content appeared garbled due to missing charset.

Changes

src/api-fetch.ts

  • Add ContentType to COS putObject params (the core fix)
  • Add ensureTextCharset() helper: appends ; charset=utf-8 to text/* types lacking charset
  • Expand inferContentType() map with text file extensions: .md, .markdown, .csv, .html, .htm, .css, .xml, .yaml, .yml

src/channel.ts

  • When download returns application/octet-stream, fall back to inferContentType(filename) to get the real type
  • Wrap contentType with ensureTextCharset() before upload

src/inbound.ts

  • Same ensureTextCharset() wrapping for inbound file re-upload path

Tests

  • 8 tests for ensureTextCharset covering text types, non-text passthrough, and existing charset preservation

Closes #137

- Add ContentType to putParams in uploadFileToCOS (was missing entirely)
- Add ensureTextCharset helper: appends ; charset=utf-8 for text/* types
- Apply at both upload call sites (inbound.ts, channel.ts)

Fixes dmwork-org#137
@Jerry-Xin Jerry-Xin force-pushed the fix/cos-upload-content-type branch from 086e253 to 4715e31 Compare March 30, 2026 08:05
@yujiawei yujiawei merged commit b3a252c into dmwork-org:main Mar 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: COS upload missing ContentType in putObject params

2 participants