ファイルをダウンロードするときの BLOB オブジェクト タイプのタイプ リストとダウンロード メソッドのカプセル化
参考記事 1 - ファイルをダウンロードするときの BLOB タイプの百科事典@Pai Daxing 1
参考記事 2 - 新しい BLOB ダウンロード ファイル ストリーム、ファイルのサフィックスに応じて BLOB タイプを動的に照合する@王新新2255
注意: 获取文件流的接口,需要配置 responseType: 'blob',
サンプルコード
onePageExport: (params) => {
return post({
url: `base/url/test`,
responseType: 'blob',
params
})
},
メソッドのカプセル化:
fileHandle(data, fileName) {
let blob = new Blob([data], {
type: 'application/pdf' })
let url = window.URL.createObjectURL(blob)
const link = document.createElement('a') // 创建a标签
link.href = url
link.download = fileName // 重命名文件
link.click()
URL.revokeObjectURL(url) // 释放内存
},
// 文件名称获取
let {
headers } = res
let filename = headers['content-disposition']
filename = decodeURIComponent(filename.split(';')[1].split('=')[1])
aac |
AACオーディオ | audio/aac |
---|---|---|
.abw |
AbiWordドキュメント | application/x-abiword |
.arc |
アーカイブドキュメント (複数のファイルが埋め込まれている) | application/x-freearc |
.avi |
AVI: オーディオ ビデオ インターリーブ | video/x-msvideo |
.azw |
Amazon Kindle 電子書籍フォーマット | application/vnd.amazon.ebook |
.bin |
あらゆる種類のバイナリデータ | application/octet-stream |
.bmp |
Windows OS/2 ビットマップ グラフィックス | image/bmp |
.bz |
BZip アーカイブ | application/x-bzip |
.bz2 |
BZip2 アーカイブ | application/x-bzip2 |
.csh |
Cシェルスクリプト | application/x-csh |
.css |
カスケード スタイル シート (CSS) | text/css |
.csv |
カンマ区切り値 (CSV) | text/csv |
.doc |
マイクロソフトワード | application/msword |
.docx |
Microsoft Word (OpenXML) | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
.eot |
MS 埋め込み OpenType フォント | application/vnd.ms-fontobject |
.epub |
電子出版(EPUB) | application/epub+zip |
.gif |
グラフィックス交換フォーマット (GIF) | image/gif |
.htm.html |
ハイパーテキスト マークアップ言語 (HTML) | text/html |
.ico |
アイコンの形式 | image/vnd.microsoft.icon |
.ics |
iCalendar形式 | text/calendar |
.jar |
Java アーカイブ (JAR) | application/java-archive |
.jpeg .jpg |
JPEG画像 | image/jpeg |
.js |
JavaScript | text/javascript |
.json |
JSON形式 | application/json |
.jsonld |
JSON-LD形式 | application/ld+json |
.mid .midi |
楽器デジタルインターフェース (MIDI) | audio/midi audio/x-midi |
.mjs |
JavaScriptモジュール | text/javascript |
.mp3 |
MP3オーディオ | audio/mpeg |
.mpeg |
MPEGビデオ | video/mpeg |
.mpkg |
Apple インストーラー パッケージ | application/vnd.apple.installer+xml |
.odp |
OpenDocument プレゼンテーション ドキュメント | application/vnd.oasis.opendocument.presentation |
.ods |
OpenDocument spreadsheet document | application/vnd.oasis.opendocument.spreadsheet |
.odt |
OpenDocument text document | application/vnd.oasis.opendocument.text |
.oga |
OGG audio | audio/ogg |
.ogv |
OGG video | video/ogg |
.ogx |
OGG | application/ogg |
.otf |
OpenType font | font/otf |
.png |
Portable Network Graphics | image/png |
.pdf |
Adobe Portable Document Format (PDF) | application/pdf |
.ppt |
Microsoft PowerPoint | application/vnd.ms-powerpoint |
.pptx |
Microsoft PowerPoint (OpenXML) | application/vnd.openxmlformats-officedocument.presentationml.presentation |
.rar |
RAR archive | application/x-rar-compressed |
.rtf |
Rich Text Format (RTF) | application/rtf |
.sh |
Bourne shell script | application/x-sh |
.svg |
Scalable Vector Graphics (SVG) | image/svg+xml |
.swf |
Small web format (SWF) or Adobe Flash document | application/x-shockwave-flash |
.tar |
Tape Archive (TAR) | application/x-tar |
.tif.tiff |
Tagged Image File Format (TIFF) | image/tiff |
.ttf |
TrueType Font | font/ttf |
.txt |
Text, (generally ASCII or ISO 8859-n) | text/plain |
.vsd |
Microsoft Visio | application/vnd.visio |
.wav |
Waveform Audio Format | audio/wav |
.weba |
WEBM audio | audio/webm |
.webm |
WEBM video | video/webm |
.webp |
WEBP image | image/webp |
.woff |
Web Open Font Format (WOFF) | font/woff |
.woff2 |
Web Open Font Format (WOFF) | font/woff2 |
.xhtml |
XHTML | application/xhtml+xml |
.xls |
Microsoft Excel | application/vnd.ms-excel |
.xlsx |
Microsoft Excel (OpenXML) | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
.xml |
XML |
application/xml 代码对普通用户来说不可读 (RFC 3023, section 3) text/xml 代码对普通用户来说可读 (RFC 3023, section 3) |
.xul |
XUL | application/vnd.mozilla.xul+xml |
.zip |
ZIP archive | application/zip |
.3gp |
3GPP audio/video container | video/3gpp audio/3gpp (若不含视频) |
.3g2 |
3GPP2 audio/video container | video/3gpp2 audio/3gpp2 (若不含视频) |
.7z |
7-zip archive | application/x-7z-compressed |