文件上传接口–文件类型与其对应的 Content-Type
图片文件
文件扩展名 | Content-Type |
---|---|
.jpg / .jpeg | image/jpeg |
.png | image/png |
.gif | image/gif |
.bmp | image/bmp |
.svg | image/svg+xml |
.webp | image/webp |
.tiff | image/tiff |
音频文件
文件扩展名 | Content-Type |
---|---|
.mp3 | audio/mpeg |
.wav | audio/wav |
.ogg | audio/ogg |
.aac | audio/aac |
.flac | audio/flac |
.midi | audio/midi |
视频文件
文件扩展名 | Content-Type |
---|---|
.mp4 | video/mp4 |
.webm | video/webm |
.avi | video/x-msvideo |
.mov | video/quicktime |
.wmv | video/x-ms-wmv |
.flv | video/x-flv |
文档文件
文件扩展名 | Content-Type |
---|---|
application/pdf | |
.doc | application/msword |
.docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
.xls | application/vnd.ms-excel |
.xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
.ppt | application/vnd.ms-powerpoint |
.pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation |
.txt | text/plain |
.rtf | application/rtf |
.csv | text/csv |
压缩文件
文件扩展名 | Content-Type |
---|---|
.zip | application/zip |
.rar | application/x-rar-compressed |
.7z | application/x-7z-compressed |
.tar | application/x-tar |
.gz | application/gzip |
编程相关文件
文件扩展名 | Content-Type |
---|---|
.js | application/javascript |
.json | application/json |
.xml | application/xml |
.html / .htm | text/html |
.css | text/css |
.php | application/x-httpd-php |
.py | text/x-python |
.java | text/x-java-source |
其他常见文件
文件扩展名 | Content-Type |
---|---|
.exe | application/x-msdownload |
.dll | application/x-msdownload |
.apk | application/vnd.android.package-archive |
.iso | application/x-iso9660-image |
.bin | application/octet-stream |
.dat | application/octet-stream |
通用类型
使用场景 | Content-Type |
---|---|
未知二进制文件 | application/octet-stream |
未知文本文件 | text/plain |
注意:
- 在文件上传安全测试中,攻击者常会尝试修改 Content-Type 来绕过验证
- 某些类型可能有多种有效的 Content-Type 表示方式
- 对于 Office 2007+ 的新格式(.docx, .xlsx, .pptx)有特定的 Content-Type
- 在实际应用中,服务器应同时验证文件内容和扩展名,而不仅依赖 Content-Type