我正在使用Angular HttpClient。从服务器上下载一个zip文件。
角度代码:
httpHeaders = ({
'Content-Type': 'application/json',
'tonic_id': this.getTonicToken()
});
observe: 'response',
headers: httpHeaders,
params: httpParams,
responseType: 'arraybuffer',
withCredentials: true
要保存压缩文件:
saveAs(new Blob([fileData], {type: "application/zip"}), "test.zip");
服务器代码是用clojure编写的:
(defresource download
[db userid target]
resource/base-resource
:allowed-methods [:get]
:available-media-type ["application/zip"]
:handle-ok (fn [_]
(try
(ring-response {:status 200
:headers {"Content-Type" "application/zip"}
:body (io/file
(:csv-dir (config/app-config))
(export-db/file-name-from-uuid
(:connection db)
userid (first (str/split target #"\."))))})
(catch Throwable t (error t) (throw t))))
:exists? (file-exists? db userid (first (str/split target #"\."))))
我可以下载zip文件,但无法解压缩。将服务器上的zip文件与创建的zip文件进行比较时,我注意到新的zip文件中有许多方块。我认为它与编码有关。
请帮助。参见下图: