Javascript Safari下载zip文件为;“未知”;获取时(使用polyfill)
我在服务器端(golang snippet)设置了这些标题,可以在不同的文件夹中压缩16个文件,这些标题在chrome和ff中都很好地工作,但在safari中不起作用。下面是Javascript代码Javascript Safari下载zip文件为;“未知”;获取时(使用polyfill),javascript,go,safari,zip,Javascript,Go,Safari,Zip,我在服务器端(golang snippet)设置了这些标题,可以在不同的文件夹中压缩16个文件,这些标题在chrome和ff中都很好地工作,但在safari中不起作用。下面是Javascript代码 .... c.Response().Header().Set("Pragma", "public") c.Response().Header().Set("Expires", "0") c.Response().Header().Set("Cache-Control", "must
....
c.Response().Header().Set("Pragma", "public")
c.Response().Header().Set("Expires", "0")
c.Response().Header().Set("Cache-Control", "must-revalidate, post-check=0, pre-check=0")
c.Response().Header().Set("Cache-Control", "public")
c.Response().Header().Set("Content-Description", "File Transfer")
c.Response().Header().Set("Content-type", "application/octet-stream")
c.Response().Header().Set("Content-Transfer-Encoding", "binary")
c.Response().Header().Set("Content-Lengthg", "177998")
// header("Content-Length: ".filesize($filepath.$filename));
filename := "launchaco.zip"
// c.Response().Header().Set("Content-Type", "application/file")
c.Response().Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename))
zw := zip.NewWriter(c.Response())
header := &zip.FileHeader{
Name: "index.html",
Method: zip.Store,
ModifiedTime: uint16(time.Now().UnixNano()),
ModifiedDate: uint16(time.Now().UnixNano()),
}
....
Javascript
fetch(document.location.origin + "/SECRET_ENDPOINT?s=" + encodeURIComponent(JSON.stringify(localStorage.getItem('structured-elm-todo-state'))))
.then(function(response) {
return response.blob();
}).then(function(blob) {
saveAs(blob, "download.zip");
setTimeout(function() {
var popup = document.getElementById("downloaded-popup");
popup.className = "downloader-popup downloader-popup__active"
}, 1000);
});
如果有人关心您使用的saveAs()库,这里是实际的生产站点?这个:?不确定这是否是原因,但这里有一个输入错误:
内容长度
。另外,您是否尝试将内容类型设置为应用程序/zip
?