Example #1
0
        /// <summary>下载</summary>
        /// <param name="doc">Xml 文档对象</param>
        /// <returns>返回操作结果</returns>
        public ActionResult Download(string options)
        {
            JsonData request = JsonMapper.ToObject(options == null ? "{}" : options);

            // 实体数据标识
            string id = !request.Keys.Contains("id") ? string.Empty : request["id"].ToString();

            IAttachmentFileInfo param = AttachmentStorageContext.Instance.AttachmentFileService[id];

            if (param == null)
            {
                KernelContext.Log.Info("file not found id:" + id);

                ApplicationError.Write(404);
            }
            else
            {
                if (param != null && param.FileData == null)
                {
                    KernelContext.Log.Info("file data is null id:" + id);

                    // 下载分布式文件数据
                    param.FileData = DistributedFileStorage.Download(param);
                }

                // [容错] 由于人为原因将服务器上的文件删除。
                if (param.FileData == null)
                {
                    ApplicationError.Write(404);
                }

                Response.ContentType = "application/octet-stream";

                Response.AddHeader("Content-Disposition", "attachment;filename=" + EncodeFileName(param.AttachmentName));
                Response.BinaryWrite(param.FileData);
            }

            Response.End();

            return(Content(string.Empty));
        }
        /// <summary>获取分页内容</summary>
        /// <param name="doc">Xml 文档对象</param>
        /// <returns>返回操作结果</returns>
        public string Download(XmlDocument doc)
        {
            this.ProcessRequest(HttpContext.Current);

            string id = HttpContext.Current.Request.QueryString["id"];

            IAttachmentFileInfo param = AttachmentStorageContext.Instance.AttachmentFileService[id];

            if (param == null)
            {
                ApplicationError.Write(404);
            }
            else
            {
                if (param != null && param.FileData == null)
                {
                    // 下载分布式文件数据
                    param.FileData = DistributedFileStorage.Download(param);
                }

                // [容错] 由于人为原因将服务器上的文件删除。
                if (param.FileData == null)
                {
                    ApplicationError.Write(404);
                }

                HttpContext.Current.Response.ContentType = "application/octet-stream";

                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + EncodeFileName(param.AttachmentName));
                HttpContext.Current.Response.BinaryWrite(param.FileData);
            }

            HttpContext.Current.Response.End();

            return(string.Empty);
        }