MIME type của tệp .xlsx là gì?
MIME type (kiểu phương tiện) của tệp Microsoft Excel có đuôi .xlsx là application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. Đây là kho lưu trữ ZIP chứa XML, đã được nén sẵn. Hãy phục vụ đúng kiểu này để trình duyệt giữ đuôi .xlsx khi tải xuống.
Header Content-Type
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8
Các kiểu dựa trên văn bản nên kèm charset để trình duyệt giải mã ký tự đúng cách.
Cấu hình máy chủ
| Máy chủ | Cấu hình |
|---|---|
Nginx (mime.types hoặc types {}) | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; |
Apache (.htaccess) | AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx |
IIS (web.config) | <mimeMap fileExtension=".xlsx" mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" /> |
| Node.js / Express | res.type('xlsx') hoặc res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8') |
| Amazon S3 | Đặt Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet cho đối tượng (metadata), hoặc truyền --content-type application/vnd.openxmlformats-officedocument.spreadsheetml.sheet vào aws s3 cp |
Tệp .xlsx có nên nén không?
Không. Tệp Microsoft Excel vốn đã được nén bên trong, nên gzip hay Brotli sẽ lãng phí CPU và hầu như không giảm dung lượng — đôi khi còn làm tăng. Đừng đưa application/vnd.openxmlformats-officedocument.spreadsheetml.sheet vào cấu hình nén.
Vì sao MIME type quan trọng
Trình duyệt quyết định sẽ làm gì với phản hồi — hiển thị, thực thi, phát hay tải xuống — dựa trên header Content-Type, chứ không phải đuôi tệp. Với X-Content-Type-Options: nosniff, kiểu sai khiến stylesheet và script bị chặn hoàn toàn. Với tệp tải lên, đừng bao giờ tin kiểu do client gửi; hãy kiểm tra nội dung tệp (magic bytes) trên server.
Tra cứu MIME type
Tìm kiếm mọi đuôi tệp và MIME type phổ biến, kèm header Content-Type sẵn sàng để sao chép.
Câu hỏi thường gặp
MIME type của .xlsx là gì?
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.Làm thế nào để đặt Content-Type cho .xlsx trong Nginx?
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; có trong khối types (thường nằm ở /etc/nginx/mime.types) rồi tải lại Nginx.