0
我使用清漆緩存一些文件,如* .doc * .png * .xls。如何從清漆緩存中獲取正確的.xls文件?
從緩存中獲取文件但是* .xls時它工作正常。
我的URI就像/attachment/show?fileId=ewer232ewe2121eeddsd
。當我從緩存中請求.xls文件時,它將返回一個名爲show
的擴展名爲.ini的文件。
我的服務器代碼:
if (StringUtil.null2Trim(attachment.getExtension()).equals("doc")
|| StringUtil.null2Trim(attachment.getExtension()).equals("docx")
|| StringUtil.null2Trim(attachment.getExtension()).equals("xlsx")
|| StringUtil.null2Trim(attachment.getExtension()).equals("xls")) {
response.setHeader("Content-Disposition", "attachment; filename=\""
+ StringUtil.gbk2Iso(attachment.getName()) + "\"");
if (StringUtil.null2Trim(attachment.getExtension()).indexOf("doc") != -1) {
response.setContentType("application/msword");
}
if (StringUtil.null2Trim(attachment.getExtension()).indexOf("xls") != -1) {
response.setContentType("application/vnd.ms-excel");
}
} else {
if (StringUtil.null2Trim(attachment.getExtension()).equals("jpg")) {
response.setContentType("image/jpeg");
} else if (StringUtil.null2Trim(attachment.getExtension()).equals("png")) {
response.setContentType("image/x-png");
} else {
response.setContentType("image/" + attachment.getExtension());
}
}
我的問題是:爲什麼我不能得到正確的文件全名像attachment.getName()+".xls"
,以及如何解決它。
PS:有沒有什麼辦法可以在varnish(vcl)中設置ContentType?
這聽起來似乎與後端服務器小程序,不光油問題。服務器返回的確切標題是什麼? – Ketola
@Ketola是的,服務器設置不正確的headers.Now它運作良好。 – lichengwu