这里写自定义目录标题
配置好正确的mime类型导致文件流下载,整理了一份常见的文件mime类型对照表,希望对大家有所帮助!
1、office
.doc==>application/vnd.ms-word
.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
.pps==>application/vnd.ms-powerpoint
.ppsx==>application/vnd.openxmlformats-officedocument.presentationml.slideshow
.pdf==>application/pdf
.odt==>application/vnd.oasis.opendocument.text
2、图像
.png==>image/png
.jpg==>image/jpeg
.jpeg==>image/jpeg
.gif==>image/gif
.bmp==>image/x-ms-bmp
.psd==>image/vnd.adobe.photoshop
.tif==>image/tiff
.tiff==>image/tiff
.wbmp==>image/vnd.wap.wbmp
.ai==>application/postscript
.eps==>application/postscript
.cdr==>application/x-cdr
3、影音
.mp3==>audio/mpeg
.mp4a==>audio/mp4
.mid==>audio/midi
.wav==>audio/wav
.wma==>audio/x-ms-wma
.ogg==>audio/ogg
.ra==>audio/x-pn-realaudio
.mp4==>video/mp4
.mov==>video/quicktime
.m4v==>video/x-m4v
.avi==>video/x-msvideo
.3gp==>video/3gpp
.webm==>video/webm
.wm==>video/x-ms-wmv
.mkv==>video/x-matroska
.flv==>video/x-flv
.dv==>video/x-dv
.asx==>video/x-ms-asf
.m3u8==>application/x-mpegURL
.swf==>application/x-shockwave-flash
4、脚本
.txt==>text/plain
.htm==>text/html
.html==>text/html
.php==>text/x-php
.js==>text/javascript
.css==>text/css
.py==>text/x-python
.rb==>text/x-ruby
.sh==>text/x-shellscript
.sql==>text/x-sql
.pl==>text/x-perl
.wml==>text/vnd.wap.wml
.xml==>application/xml
.jar==>application/java-archive
.bin==>application/octet-stream
.chm==>application/octet-stream
5、压缩
.rar==>application/x-rar
.zip==>application/zip
.tar==>application/x-tar
.gz==>application/x-gzip
.tgz==>application/x-gzip
.bz==>application/x-bzip2
.bz2==>application/x-bzip2
.tbz==>application/x-bzip2
.7z==>application/x-7z-compressed
.exe==>application/octet-stream
附录一段已经封装的文件流下载代码:
/**
* 导出的数据进行下载, (vue项目依赖elmentUI,请自行安装)
*/
export function downloadFileFormate(res: BlobPart, fileName: string, type?: string) {
let flieType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
if (type) {
flieType = type
}
const blob = new Blob([res], {
type: flieType,
})
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = fileName
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement) // 下载完成移除元素
window.URL.revokeObjectURL(href) // 释放掉blo
ElMessage({
type: 'success',
message: '下载成功!'
})
}