Bug Description
When using gws gmail users drafts create --upload <file.eml>, the uploaded file's MIME type is always set to application/octet-stream, causing the Gmail API to reject it with:
Media type 'application/octet-stream' is not supported.
The Gmail API requires message/rfc822 for draft/message uploads.
Root Cause
In src/executor.rs, build_multipart_body() reads the MIME type from the request body's mimeType field (lines 740-745):
let media_mime = metadata
.as_ref()
.and_then(|m| m.get("mimeType"))
.and_then(|v| v.as_str())
.unwrap_or("application/octet-stream");
This works for Drive uploads where mimeType is a valid body field (e.g., --json '{"name": "file.pdf", "mimeType": "application/pdf"}').
However, for Gmail uploads, the body schema only allows {"message": {...}, "id": "..."} — there is no mimeType field. Schema validation rejects any attempt to add one:
$ gws gmail users drafts create --params '{"userId": "me"}' \
--json '{"message": {"threadId": "..."}, "mimeType": "message/rfc822"}' \
--upload message.eml
Error: Request body failed schema validation:
- mimeType: Unknown property. Valid properties: ["id", "message"]
So the MIME type always falls back to application/octet-stream, making Gmail uploads impossible.
Suggested Fix
When mimeType is not present in the body metadata, the CLI could:
- Infer from file extension:
.eml → message/rfc822, .pdf → application/pdf, etc.
- Use API-specific defaults: Gmail endpoints could default to
message/rfc822 instead of application/octet-stream.
- Add a
--upload-type flag: Let users specify the MIME type explicitly (e.g., --upload-type message/rfc822).
Steps to Reproduce
- Create a valid RFC 2822 email file (e.g.,
message.eml)
- Run:
gws gmail users drafts create \
--params '{"userId": "me"}' \
--json '{"message": {"threadId": "abc123"}}' \
--upload message.eml
- Observe error:
Media type 'application/octet-stream' is not supported.
Environment
- gws version: 0.6.0
- OS: macOS (Darwin, aarch64)
Affected APIs
This likely affects all Google APIs that require specific upload MIME types and don't have mimeType in their body schema (Gmail being the most notable).
Bug Description
When using
gws gmail users drafts create --upload <file.eml>, the uploaded file's MIME type is always set toapplication/octet-stream, causing the Gmail API to reject it with:The Gmail API requires
message/rfc822for draft/message uploads.Root Cause
In
src/executor.rs,build_multipart_body()reads the MIME type from the request body'smimeTypefield (lines 740-745):This works for Drive uploads where
mimeTypeis a valid body field (e.g.,--json '{"name": "file.pdf", "mimeType": "application/pdf"}').However, for Gmail uploads, the body schema only allows
{"message": {...}, "id": "..."}— there is nomimeTypefield. Schema validation rejects any attempt to add one:So the MIME type always falls back to
application/octet-stream, making Gmail uploads impossible.Suggested Fix
When
mimeTypeis not present in the body metadata, the CLI could:.eml→message/rfc822,.pdf→application/pdf, etc.message/rfc822instead ofapplication/octet-stream.--upload-typeflag: Let users specify the MIME type explicitly (e.g.,--upload-type message/rfc822).Steps to Reproduce
message.eml)Media type 'application/octet-stream' is not supported.Environment
Affected APIs
This likely affects all Google APIs that require specific upload MIME types and don't have
mimeTypein their body schema (Gmail being the most notable).