using BizCom; using NPOI.SS.Formula.Functions; using SiteCore; using SiteCore.taobao; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Utils.ImageUtils; public partial class plug_uploadFileOss : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string file_url = Request["url"]; try { if (file_url == null) { Response.Write("{\"res\":\"0\",\"msg\":\"错误的下载访问!\"}"); Response.End(); return; } Uri uri = new Uri(file_url); // 获取路径中的文件名(包含后缀) string fileName = System.IO.Path.GetFileName(uri.AbsolutePath); string filePath = "D://temp/" + fileName; WebClient webClient = new WebClient(); if (Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } webClient.DownloadFile(file_url, filePath); jiemiUtils.ossFileDecrypt(filePath); FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.Clear(); // Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开\\fileDownload=true; path=/ Response.AddHeader("Set-Cookie", "fileDownload=true; path=/;"); //Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate"); Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", bytes.Length.ToString()); Response.AddHeader("Access-Control-Expose-Headers", "Content-Disposition"); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); File.Delete(filePath); return; } catch (Exception ex) { Response.Write("{\"res\":\"0\",\"msg\":\"发生错误!" + ex.Message + "!\"}"); Response.End(); return; } } }