最近做文件下載因為涉及到不同類型的文件,所以重新查閱了一下文件所對應的的content-type類型,好記性不如爛筆頭,記錄一下。
| 文件后綴 | MIME TYPE |
|---|---|
| .doc | application/msword |
| .dot | application/msword |
| .docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
| .dotx | application/vnd.openxmlformats-officedocument.wordprocessingml.template |
| .docm | application/vnd.ms-word.document.macroEnabled.12 |
| .dotm | application/vnd.ms-word.template.macroEnabled.12 |
| .xls | application/vnd.ms-excel |
| .xlt | application/vnd.ms-excel |
| .xla | application/vnd.ms-excel |
| .xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
| .xltx | application/vnd.openxmlformats-officedocument.spreadsheetml.template |
| .xlsm | application/vnd.ms-excel.sheet.macroEnabled.12 |
| .xltm | application/vnd.ms-excel.template.macroEnabled.12 |
| .xlam | application/vnd.ms-excel.addin.macroEnabled.12 |
| .xlsb | application/vnd.ms-excel.sheet.binary.macroEnabled.12 |
| .ppt | application/vnd.ms-powerpoint |
| .pot | application/vnd.ms-powerpoint |
| .pps | application/vnd.ms-powerpoint |
| .ppa | application/vnd.ms-powerpoint |
| .pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation |
| .potx | application/vnd.openxmlformats-officedocument.presentationml.template |
| .ppsx | application/vnd.openxmlformats-officedocument.presentationml.slideshow |
| .ppam | application/vnd.ms-powerpoint.addin.macroEnabled.12 |
| .pptm | application/vnd.ms-powerpoint.presentation.macroEnabled.12 |
| .potm | application/vnd.ms-powerpoint.presentation.macroEnabled.12 |
| .ppsm | application/vnd.ms-powerpoint.slideshow.macroEnabled.12 |
| .zip | application/zip |
| .tar | application/x-tar |
以上總結參考來源(https://blog.csdn.net/xiaoranzhizhu/article/details/70473734)
接下來再補充一下基礎知識
什么是 Content-type
Content-type是實體首部字段,用於說明請求或返回的消息是用什么格式進行編碼的,在request header和response header里都有存在。 用來向服務器或者瀏覽器說明傳輸的文件格式,以便服務器和瀏覽器按照正確的格式進行解析。在最初的的http post請求只支持application/x-www-form-urlencoded,參數是通過瀏覽器的url進行傳遞,但此種方法不支持文件上傳,所以后來Content-type 擴充了multipart/form-data類型以支持向服務器發送二進制數據,以及隨着后面web應用的日益發展增加了application/json的類型
幾種常見類型
1:application/x-www-form-urlencoded
form表單提交的默認值,傳輸數據都是以key=value(key1=val1&key2=val2)格式進行編碼,並且key和value都進行了編碼(Content-Type: application/x-www-form-urlencoded;charset=utf-8
name=%E9%BB%84%E6%99%93%E6%98%8E&age=40)
2:multipart/form-data
指定傳輸數據為二進制數據,專門用於傳輸文件,例如圖片、mp3、文件等,在文件、圖片等上傳的時候要設置request的content-type 為multipart/form-data類型
例如:

圖片上傳Content-type類型
3:application/json
此類型告訴服務端數據是序列化的json字符串,由於json規范的流行和越來越多的瀏覽器支持原生JSON.stringfy,此類型也越來越多的被使用。
(最后發送到服務端的數據格式eg:"{'name':'黃曉明','age':'40'}")
另外還有
application/xhtml+xml :XHTML格式
application/xml : XML數據格式
application/atom+xml :Atom XML聚合格式
application/json : JSON數據格式
application/pdf :pdf格式
application/msword : Word文檔格式
application/octet-stream : 二進制流數據(如常見的文件下載)
...等等
