예제 #1
0
 /// <summary>
 /// 校验时效获取文件数据流
 /// </summary>
 /// <param name="guid">与获取文件路径中的文件名称一致</param>
 /// <param name="path"></param>
 /// <param name="access_token"></param>
 /// <returns></returns>
 public FileStreamResult GetFile(Guid guid, string path, string access_token)
 {
     try
     {
         string name = Path.GetFileName(path);
         WOPI   wopi = new WOPI(service);
         if (!wopi.Validate(name, access_token))
         {
             var stream = new MemoryStream(UTF8Encoding.Default.GetBytes(""));
             return(File(stream, "application/octet-stream"));
         }
         //var config = service.GetDicItemsByCode("FileServer");
         var fileserver = _dictionaryContext[SettingType.FileServer, SettingVariable.FileServerPath]; // config.First(f => f.Name == "FileServerPath").Value;
         var account    = _dictionaryContext[SettingType.FileServer, SettingVariable.Account];        // config.First(f => f.Name == "Account").Value;
         var password   = _dictionaryContext[SettingType.FileServer, SettingVariable.Password];       // config.First(f => f.Name == "Password").Value;
         if (ConnectFileServerHelp.ConnectFileServer(fileserver, account, password))
         {
             var stream      = new FileStream(path, FileMode.Open);
             var contentType = MimeMapping.GetMimeMapping(path);
             return(File(stream, contentType));
         }
         else
         {
             throw new Exception("连接文件服务器失败");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #2
0
        /// <summary>
        /// 获取文件信息
        /// </summary>
        /// <param name="guid">与获取文件路径中的文件名称一致</param>
        /// <param name="path"></param>
        /// <param name="access_token"></param>
        /// <returns></returns>
        public JsonResult GetFileInfo(Guid guid, string path, string access_token)
        {
            string name = Path.GetFileName(path);
            WOPI   wopi = new WOPI(service);

            if (!wopi.Validate(name, access_token))
            {
                return(Json(new CheckFileInfo(), JsonRequestBehavior.AllowGet));
            }

            var fileInfo = wopi.GetFileInfo(path);

            fileInfo.SupportsUpdate = false;
            fileInfo.UserCanWrite   = false;
            fileInfo.SupportsLocks  = false;

            return(Json(fileInfo, JsonRequestBehavior.AllowGet));
        }