// 初始化信息 void Init(HttpContext context) { this.ctx = context; isLog = string.IsNullOrEmpty(ctx.Request.QueryString["IsLog"]) ? false : bool.Parse(ctx.Request.QueryString["IsLog"]); long fileLength = string.IsNullOrEmpty(ctx.Request.QueryString["FileLength"]) ? 0 : long.Parse(ctx.Request.QueryString["FileLength"]); string src = ctx.Request.QueryString["src"]; string filename = ctx.Request.QueryString["filename"]; // 客户端最后写入时间,考虑到效率,据此简单判断客户端文件是否改变,断点续传时使用(如用HashCode对大文件影响效率) //string clientLastWriteFileTime = Func.AttrIsNull(ctx.Request.QueryString["LastWriteFileTime"]) ? String.Empty : ctx.Request.QueryString["LastWriteFileTime"]; // 获取文件信息状态 //fileInfo = new UploadFileInfo(userState.UserId, filename, clientLastWriteFileTime, fileSize); uploadConfig = UploadHelper.RetrieveConfig(); fileInfo = new UploadFileInfo("USERID", filename, fileLength); // 开始上传 long startByte = string.IsNullOrEmpty(ctx.Request.QueryString["StartByte"]) ? 0 : long.Parse(ctx.Request.QueryString["StartByte"]); // 并不是获取上传字节 bool getBytes = string.IsNullOrEmpty(context.Request.QueryString["GetBytes"]) ? false : bool.Parse(context.Request.QueryString["GetBytes"]); if (startByte == 0 && !getBytes) { this.WriteLog("Upload Begin"); } }
private void RetrieveInitParams() { UploadConfig config = new UploadConfig(); string fileMode = string.IsNullOrEmpty(Request["FileMode"]) ? "Multi" : Request["FileMode"]; string bMaximumUpload = Request["MaximumUpload"]; string maximumUpload = String.Empty; if (string.IsNullOrEmpty(bMaximumUpload)) { maximumUpload = ConverterM2B(config.MaxFileSize); } else { maximumUpload = ConverterM2B(float.Parse(bMaximumUpload)); } string filter = HttpUtility.UrlDecode(string.IsNullOrEmpty(Request["Filter"]) ? "" : Request["Filter"]); if (string.IsNullOrEmpty(filter)) { filter = config.FileFilter; } string maxNumberToUpload = Request["MaxNumberToUpload"]; if (string.IsNullOrEmpty(maxNumberToUpload)) { maxNumberToUpload = config.MaxFileNumber.ToString(); } string allowThumbnail = string.IsNullOrEmpty(Request["AllowThumbnail"]) ? "" : Request["AllowThumbnail"].ToLower(); if (string.IsNullOrEmpty(allowThumbnail)) { allowThumbnail = config.AllowThumbnail.ToString(); } string isLog = string.IsNullOrEmpty(Request["IsLog"]) ? "" : Request["IsLog"].ToLower(); if (string.IsNullOrEmpty(isLog)) { isLog = config.IsLog.ToString(); } string _initParams = String.Empty; //增加RelateId by dingx_new 2011-7-25 //string uploadPage = Server.UrlPathEncode(config.HandlerPage); string uploadPage = Server.UrlPathEncode(GetUploadHandlerUrl()); //动态上传地址 2013-11 by dingx_new if (uploadPage.Contains('?')) { uploadPage += "&RelateId=" + this.Request.QueryString["RelateId"] + "&Src=" + this.Request.QueryString["Src"]; } else { uploadPage += "?RelateId=" + this.Request.QueryString["RelateId"] + "&Src=" + this.Request.QueryString["Src"]; } _initParams += //"UploadPage=" + Server.UrlPathEncode(config.HandlerPage + "?PassCode=" + this.PassCode) + "," "UploadPage=" + uploadPage + "," + "FileMode=" + fileMode + "," + "MaximumUpload=" + maximumUpload + "," + "Filter=" + filter + "," + "MaxNumberToUpload=" + maxNumberToUpload + "," + "AllowThumbnail=" + allowThumbnail + "," + "IsLog=" + isLog + "," + "ContinueSize=" + config.ContinueSize + "," + "MaximumTotalUpload=-1,UploadChunkSize=4194304,MaxConcurrentUploads=1,ResizeImage=False,ImageSize=300," + "Multiselect=True,JsCompleteFunction=OnComplete,JsCancelFunction=OnCancel,JsCheckFunction=OnCheck"; this.InitParams = _initParams; }
//// 获取上传得临时文件夹路径, 也即原Ftp目录路径 //public static string GetTemparatoryDirectory() //{ // return Config.File_TemparatoryDirectory; //} // 获取上传信息配置s public static UploadConfig RetrieveConfig() { UploadConfig _config = new UploadConfig(); return(_config); }
public void ProcessRequest(HttpContext context, string uploadPath, UploadFileInfo fileInfo, UploadConfig uploadConfig) { // 是否已上传完毕 bool complete = string.IsNullOrEmpty(context.Request.QueryString["Complete"]) ? true : bool.Parse(context.Request.QueryString["Complete"]); // 获取上传进度操作标识 bool getBytes = string.IsNullOrEmpty(context.Request.QueryString["GetBytes"]) ? false : bool.Parse(context.Request.QueryString["GetBytes"]); // 上传开始位置,用于断点续传 long startByte = string.IsNullOrEmpty(context.Request.QueryString["StartByte"]) ? 0 : long.Parse(context.Request.QueryString["StartByte"]); // 服务器端文件路径 string filePath = Path.Combine(uploadPath, fileInfo.FileString); FileHelper.CheckFileFullPath(filePath); if (getBytes) { filePath = filePath.Replace("+", "%2b"); FileInfo fi = new FileInfo(HttpContext.Current.Server.UrlDecode(filePath)); if (!fi.Exists) { context.Response.Write("0"); } else { context.Response.Write(fi.Length.ToString()); } context.Response.Flush(); return; } else { if (startByte > 0 && File.Exists(filePath)) { using (FileStream fs = File.Open(filePath, FileMode.Append)) { SaveFile(context.Request.InputStream, fs); fs.Close(); } } else { using (FileStream fs = File.Create(filePath)) { SaveFile(context.Request.InputStream, fs); fs.Close(); } } if (complete) { if (FileUploadCompleted != null) { FileUploadCompletedEventArgs args = new FileUploadCompletedEventArgs(fileInfo.FileName, filePath); FileUploadCompleted(this, args); } } } }