[英]Download a .gz file using jQuery
我必須調用遠程服務來下載一個 gzipped 文件 (csv.gz)。 我必須使用 jQuery,因為我必須設置身份驗證 HTTP 標頭。 我試過這樣的事情:
$.ajax({
type: "GET",
url: url
}).done(function (res) {
const a = document.createElement('a');
a.style = 'display: none';
document.body.appendChild(a);
const blob = new Blob([res]);
const url = URL.createObjectURL(blob);
a.href = url;
a.download = _this.attributes.id + '.' + _DEFAULT_DOWNLOADED_FILE_EXTENTION;
a.click();
URL.revokeObjectURL(url);
}).fail(function (err) { });
我可以下載該文件,但下載后,我嘗試將其解壓縮到我的電腦上,但該文件不正確(已損壞)。 可能我使用的 Blob 創建不正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.