Esempio n. 1
0
        public async Task <SysFile> InsertAsync(SysFile file)
        {
            var id = await _dg.InsertOneAsync("SaveFile", file);

            file.Id = id;
            return(file);
        }
Esempio n. 2
0
        private SysFile BuildNew(ServerUploadRequest request)
        {
            var doc = new SysFile
            {
                Name       = request.FileName,
                CreateTime = DateTime.Now,
                UserId     = request.UserId
            };

            var ext = Path.GetExtension(request.FileName);

            var level1Dir = doc.CreateTime.ToString("yyyyMM");
            var level2Dir = doc.CreateTime.ToString("ddHH");
            var docPath   = $@"{this._uploadPath}\{level1Dir}\{level2Dir}";

            if (!Directory.Exists(docPath))
            {
                Directory.CreateDirectory(docPath);
            }
            doc.RelativePath = $@"\{level1Dir}\{level2Dir}\{Guid.NewGuid().ToString("N")}{ext}";
            doc.ContentType  = IOHelper.GetContentType(request.FileName);
            return(doc);
        }
Esempio n. 3
0
        DownloadResult DownloadAsync(DownloadRequest request, SysFile file)
        {
            var result = new DownloadResult();

            result.FileName = request.FileName; //wang加
            var relativePath = request.ContentRef.Replace('/', '\\');

            if (result.FileName.IsEmpty())
            {
                result.FileName = Path.GetFileName(relativePath);
            }
            var filePath = this._uploadPath + relativePath;

            if (File.Exists(filePath))
            {
                result.Content = File.OpenRead(filePath);
            }
            else
            {
                throw new Exception("指定文件不存在");
            }
            result.ContentType = file.ContentType;
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 根据指定SysFile文件实体信息下载文件,即使SysFile不在数据库中
        /// </summary>
        /// <param name="file">SysFile文件实体信息</param>
        /// <returns>文件下载结果</returns>
        public DownloadResult Download(SysFile file)
        {
            var result = new DownloadResult();

            result.FileName = file.Name;
            var relativePath = file.RelativePath;

            if (result.FileName.IsEmpty())
            {
                result.FileName = Path.GetFileName(relativePath);
            }
            var filePath = this._uploadPath + relativePath;

            if (File.Exists(filePath))
            {
                result.Content = File.OpenRead(filePath);
            }
            else
            {
                throw new Exception("指定文件不存在");
            }
            result.ContentType = file.ContentType;
            return(result);
        }
Esempio n. 5
0
 /// <summary>
 /// 复制一个相同的文件信息记录,指向同一个物理文件,只是逻辑文件名不同
 /// </summary>
 /// <returns></returns>
 public async Task <string> Duplicate(SysFile file)
 {
     file.Id = null;
     return(await _dg.InsertOneAsync("SaveFile", file));
 }