Exemple #1
0
 public FileStreamResult Preview(
     FileNode target,
     Guid key) {
     if (!PreviewKeyCheck.Check(target.Id, key)) {
         throw new AuthorizeException("錯誤的Key,請確認該Key未過期且尚未使用過");
     }
     return File(target.GetFileStream(), target.ContentType, $"{target.Name}.{target.Ext}");
 }
Exemple #2
0
        public FileStreamResult Download(FileNode target) {
            if (!target.HasReadAuthority(User, Database)) {
                throw new AuthorizeException("無權限存取該目標");
            }
            target.Download++;
            Database.SaveChanges();
            if (target.IsFile) {
                return File(target.GetFileStream(), target.ContentType, target.FullName);
            } else {
                var FilePath = target.GetAndCreateDirZipFileRealPath(User, Database);
                Response.OnCompleted(async (filePath) => {
                    System.IO.File.Delete((string)filePath);
                },FilePath);

                return File(
                    new FileStream(FilePath, FileMode.Open),
                    "application/zip", 
                    $"{target.Name}.zip");
            }
        }