Esempio n. 1
0
        /// <summary>保存附件信息</summary>
        public static void Upload(IAttachmentFileInfo file)
        {
            // -------------------------------------------------------
            // 保存 数据库
            // 数据库 支持数据库集群
            // -------------------------------------------------------

            if (AttachmentStorageConfigurationView.Instance.DistributedFileStorageMode == "ON")
            {
                DistributedFileInfo param = new DistributedFileInfo();

                param.Id          = file.Id;
                param.VirtualPath = file.VirtualPath;
                param.FileData    = file.FileData;

                AttachmentStorageContext.Instance.AttachmentDistributedFileService.Save(param);
            }

            // -------------------------------------------------------
            // 保存 二进制数据
            // -------------------------------------------------------

            string path = UploadPathHelper.CombinePhysicalPath(file.Parent.AttachmentFolder, string.Format("{0}{1}", file.Id, file.FileType));

            if (!File.Exists(path))
            {
                UploadPathHelper.TryCreateDirectory(path);

                ByteHelper.ToFile(file.FileData, path);
            }
        }
Esempio n. 2
0
        /// <summary>获取附件信息</summary>
        public static byte[] Download(IAttachmentFileInfo file)
        {
            DistributedFileInfo param = AttachmentStorageContext.Instance.AttachmentDistributedFileService.FindOne(file.Id);

            if (param == null)
            {
                return(null);
            }
            else
            {
                string path = file.VirtualPath.Replace("{uploads}", AttachmentStorageConfigurationView.Instance.PhysicalUploadFolder);

                UploadPathHelper.TryCreateDirectory(path);

                ByteHelper.ToFile(param.FileData, path);

                return(param.FileData);
            }
        }