遇到下载MP4文件、text文件的情况 浏览器直接打开了 解决方案
js
function getDownLoadUrl(url)
{
$.ajax({
type : "post",
dataType : "json",
url : "vod-info!getDownLoadurl.htm",
data : {
url: url,
},
async : false,
success : function(data) {
if (data.success) {
window.location.href=data.url;
}
}
});
}
java代码
public void getDownLoadurl(){
String url = this.getPara("url");
Map<String, Object> resultMap = new HashMap<String, Object>();
boolean result = false;
if (StringKit.isEmpty(url)) {
resultMap.put("success", result);
this.renderJson(resultMap);
return;
}
String fileName = url.substring(url.lastIndexOf("/")+1);
String upload_path = Constants.UPLOADS_PATH;
String uploadpath = upload_path + File.separator + this.getSession().getAttribute("uid").toString()
+ File.separator + fileName;
final Map<String, String> headers = new HashMap<String, String>();
headers.put("pragma", "no-cache");
headers.put("cache-control", "no-cache");
headers.put("Content-Type", "text/xml");
result = HttpKit.downloadFile(url, headers, uploadpath);
String downloadurl = Constants.LOCAL_SERVICE_URL+"uploads/"+this.getSession().getAttribute("uid").toString()+ File.separator + fileName;
resultMap.put("url", downloadurl);
resultMap.put("success", result);
this.renderJson(resultMap);
}