public static string FileDownURL(IFile file) { if (file is Attachment) { file = file as Attachment; } else if (file is IESFile) { file = file as IESFile; } else if (file is IES.Resource.Model.File) { file = file as IES.Resource.Model.File; } ResourceServer server = StoreServie.ResourceServer_Get(file.ServerID); return(string.Format(downurl, server.Host, server.IISPort, server.IISFolder, file.FileName)); }
/// <summary> /// 文件在线浏览地址 :TODO /// </summary> /// <param name="file"></param> /// <returns></returns> public static string FileViewURL(IFile file) { if (file is Attachment) { file = file as Attachment; } else if (file is IESFile) { file = file as IESFile; } else if (file is IES.Resource.Model.File) { file = file as IES.Resource.Model.File; } string ext = StringHelp.GetFileNameExt(file.FileName).ToLower(); ResourceServer server = StoreServie.ResourceServer_Get(file.ServerID); return(string.Format(downurl, server.Host, server.NginxPort, server.NginxFolder, file.FileName)); }
private static IESFile _upload(Stream inputStream, string fileName) { ResourceServer server = StoreServie.ResourceServer_Fast_Get(); string machineName = server.Host; string httpPort = server.IISPort; string webFolder = server.IISFolder; string PubKey = server.PubKey; string filehead = Guid.NewGuid().ToString(); string Ext = Path.GetExtension(fileName); string newFileName = filehead + Ext; string code = IES.Common.Secret.Hash.GetMD5(newFileName + PubKey + server.ServerID.ToString()); string uri = string.Format("http://{0}:{1}/{2}/HttpUpload/HttpUpload.ashx?code={3}&fileName={4}&UName=able&PWD=able&SID={5}", machineName, httpPort, webFolder, code, newFileName, server.ServerID.ToString()); HttpWebRequest webRequest = WebRequest.Create(uri) as HttpWebRequest; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = inputStream.Length; webRequest.Timeout = 99999999; webRequest.Method = "POST"; webRequest.AllowWriteStreamBuffering = false; bool iscorrect = true; using (Stream fStream = inputStream) { using (Stream requestStream = webRequest.GetRequestStream()) { try { byte[] buff = new byte[40960]; int len = 0; while ((len = fStream.Read(buff, 0, buff.Length)) > 0) { requestStream.Write(buff, 0, len); fStream.Flush(); requestStream.Flush(); } WebResponse webResponse = webRequest.GetResponse(); } catch { iscorrect = false; } } } IESFile file = new IESFile(); if (iscorrect) { file.ServerID = server.ServerID; file.FileName = newFileName; file.FileGuid = filehead; file.UserID = UserService.CurrentUser.UserID; file.FileSize = webRequest.ContentLength; file.FileTitle = fileName; file.Ext = Ext; } return(file); }