我设置了这些标题服务器端(golang片段),它在不同的文件夹中压缩了16个文件,这一切都很好,并且在chrome和ff中很好,但是在safari中不起作用。 Javascript代码在下面
....
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);
});