Skype机器人无法发送本地文件附件,提示MIME type is Invalid
Hey there, let's break down how to resolve that frustrating "MIME type is Invalid" error you're seeing in Skype, while also making sure you can send the file's location link successfully. First, let's clarify why this works in the simulator but not in Skype—Skype has stricter validation rules for attachments compared to the Bot Framework simulator, so we need to adjust our approach accordingly.
Key Issues & Solutions
1. Use Exact, Valid MIME Types (Not Generic Ones)
Skype rejects generic MIME types like application/octet-stream for most file types. You need to specify the precise MIME type matching your file format. Here are some common examples:
- PDF:
application/pdf - Word (docx):
application/vnd.openxmlformats-officedocument.wordprocessingml.document - Excel (xlsx):
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - Image (PNG):
image/png
Bad Practice: Using application/octet-stream for all files
Good Practice: Look up the official MIME type for your file format and use that explicitly.
2. Host Files on a Public HTTPS Server (No Local Paths)
The Bot Framework simulator lets you use local file paths because it runs on your machine, but Skype's servers can't access your local filesystem. You must upload your file to a cloud storage service (like Azure Blob Storage, AWS S3, or any service that provides a public HTTPS URL) and use that URL as the attachment's contentUrl.
Make sure:
- The URL uses HTTPS (Skype doesn't allow HTTP links for attachments)
- The storage service allows public access to the file (or uses a signed URL if you need restricted access)
- CORS policies are configured to allow Skype's domains to access the file (if required)
3. Correctly Structure the Attachment in Your Code
Here's a code example (using C# and Bot Framework) that properly constructs the attachment with a valid MIME type and public URL, plus includes the file location link in the message text:
using Microsoft.Bot.Schema; // Create the file attachment with valid MIME type and HTTPS URL var fileAttachment = new Attachment { Name = "Quarterly_Report.pdf", ContentType = "application/pdf", // Exact MIME type for PDF ContentUrl = "https://your-cloud-storage.example.com/files/Quarterly_Report.pdf" // Public HTTPS URL }; // Build the reply message: includes the attachment and a clickable link var replyMessage = MessageFactory.Attachment(fileAttachment); replyMessage.Text = $"Here's your requested file! You can also download it directly from: [Cloud Storage Link](https://your-cloud-storage.example.com/files/Quarterly_Report.pdf)"; // Send the message to the user await turnContext.SendActivityAsync(replyMessage, cancellationToken);
4. Check File Size Limits
Skype has a maximum file size limit for attachments (typically around 25MB, though this can vary slightly by file type). If your file is larger than this, you'll need to either compress it or send only the download link instead of the attachment.
Additional Tips
- Always test your attachment in Skype directly (not just the simulator) to catch validation issues early
- If you're using signed URLs for restricted access, ensure the URL doesn't expire before the user has a chance to download the file
- For non-standard file types, double-check the official MIME type list to avoid mismatches
内容的提问来源于stack exchange,提问作者Naveen Prasath

