void file_del() { var id = Request.QueryString["id"]; SqlExec se = new SqlExec(); se.update("up6_folders" , new SqlParam[] { new SqlParam("f_deleted", true) } , new SqlParam[] { new SqlParam("f_id", id) , new SqlParam("f_pid", id) , new SqlParam("f_pidRoot", id) } , "or" ); se.update("up6_files" , new SqlParam[] { new SqlParam("f_deleted", true) } , new SqlParam[] { new SqlParam("f_id", id) , new SqlParam("f_pid", id) , new SqlParam("f_pidRoot", id) } , "or" ); PageTool.to_content(new JObject { { "ret", 1 } }); }
void file_proc() { string fid = Request.QueryString["id"]; string uid = Request.QueryString["uid"]; string lenLoc = Request.QueryString["lenLoc"]; string per = Request.QueryString["perLoc"]; string cbk = Request.QueryString["callback"]; // if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(fid) || string.IsNullOrEmpty(cbk) || string.IsNullOrEmpty(lenLoc)) { Response.Write(cbk + "({\"value\":0})"); Response.End(); return; } DnFile db = new DnFile(); db.process(fid, int.Parse(uid), lenLoc, per); PageTool.to_content(cbk + "({\"value\":1})"); }
void file_del() { string fid = Request.QueryString["id"]; string uid = Request.QueryString["uid"]; string cbk = Request.QueryString["callback"]; if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(fid)) { Response.Write(cbk + "({\"value\":null})"); return; } DnFile db = new DnFile(); db.Delete(fid, int.Parse(uid)); PageTool.to_content(cbk + "({\"value\":1})"); }
void file_init() { string id = Request.QueryString["id"]; string uid = Request.QueryString["uid"]; string fdTask = Request.QueryString["fdTask"]; string nameLoc = Request.QueryString["nameLoc"]; //客户端使用的是encodeURIComponent编码, string pathLoc = Request.QueryString["pathLoc"]; //客户端使用的是encodeURIComponent编码, string lenSvr = Request.QueryString["lenSvr"]; string sizeSvr = Request.QueryString["sizeSvr"]; string cbk = Request.QueryString["callback"]; //应用于jsonp数据 pathLoc = HttpUtility.UrlDecode(pathLoc); //utf-8解码 nameLoc = HttpUtility.UrlDecode(nameLoc); sizeSvr = HttpUtility.UrlDecode(sizeSvr); if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(pathLoc) || string.IsNullOrEmpty(lenSvr)) { Response.Write(cbk + "({\"value\":null})"); Response.End(); return; } down2.model.DnFileInf inf = new down2.model.DnFileInf(); inf.id = id; inf.uid = int.Parse(uid); inf.nameLoc = nameLoc; inf.pathLoc = pathLoc;//记录本地存储位置 inf.lenSvr = long.Parse(lenSvr); inf.sizeSvr = sizeSvr; inf.fdTask = fdTask == "1"; DnFile db = new DnFile(); db.Add(ref inf); string json = JsonConvert.SerializeObject(inf); json = HttpUtility.UrlEncode(json); json = json.Replace("+", "%20"); json = cbk + "({\"value\":\"" + json + "\"})";//返回jsonp格式数据。 PageTool.to_content(json); }
void folder_complete() { string id = Request.QueryString["id"]; string uid = Request.QueryString["uid"]; string cak = Request.QueryString["callback"]; int ret = 0; if (string.IsNullOrEmpty(id) || uid.Length < 1) { } else { FileInf inf = new FileInf(); DBFile db = new DBFile(); db.read(id, ref inf); string root = inf.pathSvr; //上传完毕 DBFile.fd_complete(id, uid); //扫描文件夹结构, fd_scan sa = new fd_scan(); sa.root = inf;// sa.scan(inf, root); //更新扫描状态 SqlExec se = new SqlExec(); se.update("up6_folders", new SqlParam[] { new SqlParam("f_scan", true) }, new SqlParam[] { new SqlParam("f_id", id) , new SqlParam("f_uid", uid) }); up6_biz_event.folder_post_complete(id); ret = 1; } PageTool.to_content(cak + "(" + ret + ")"); }
void file_process() { string id = Request.QueryString["id"]; string uid = Request.QueryString["uid"]; string offset = Request.QueryString["offset"]; string lenSvr = Request.QueryString["lenSvr"]; string perSvr = Request.QueryString["perSvr"]; string callback = Request.QueryString["callback"]; //jsonp参数 string json = callback + "({\"state\":0})"; //返回jsonp格式数据。 if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(lenSvr) && !string.IsNullOrEmpty(perSvr)) { DBFile db = new DBFile(); db.f_process(int.Parse(uid), id, long.Parse(offset), long.Parse(lenSvr), perSvr); up6_biz_event.file_post_process(id); json = callback + "({\"state\":1})";//返回jsonp格式数据。 } PageTool.to_content(json); }
void file_complete() { string md5 = Request.QueryString["md5"]; string uid = Request.QueryString["uid"]; string id = Request.QueryString["id"]; string cbk = Request.QueryString["callback"]; //返回值。1表示成功 int ret = 0; if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(id)) { }//参数不为空 else { DBFile db = new DBFile(); db.complete(id); up6_biz_event.file_post_complete(id); ret = 1; } PageTool.to_content(cbk + "(" + ret + ")");//必须返回jsonp格式数据 }
void folder_init() { string id = Request.QueryString["id"]; string pid = Request.QueryString["pid"]; string pidRoot = Request.QueryString["pidRoot"]; string uid = Request.QueryString["uid"]; string lenLoc = Request.QueryString["lenLoc"]; string sizeLoc = Request.QueryString["sizeLoc"]; string pathLoc = HttpUtility.UrlDecode(Request.QueryString["pathLoc"]); string callback = Request.QueryString["callback"];//jsonp参数 if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(pathLoc) ) { Response.Write(callback + "({\"value\":null})"); return; } FileInf fileSvr = new FileInf(); fileSvr.id = id; fileSvr.pid = pid; fileSvr.pidRoot = pidRoot; fileSvr.fdChild = false; fileSvr.fdTask = true; fileSvr.uid = int.Parse(uid);//将当前文件UID设置为当前用户UID fileSvr.nameLoc = Path.GetFileName(pathLoc); fileSvr.pathLoc = pathLoc; fileSvr.lenLoc = Convert.ToInt64(lenLoc); fileSvr.sizeLoc = sizeLoc; fileSvr.deleted = false; fileSvr.nameSvr = fileSvr.nameLoc; //生成存储路径 PathBuilderUuid pb = new PathBuilderUuid(); fileSvr.pathSvr = pb.genFolder(ref fileSvr); fileSvr.pathSvr = fileSvr.pathSvr.Replace("\\", "/"); if (!Directory.Exists(fileSvr.pathSvr)) { Directory.CreateDirectory(fileSvr.pathSvr); } //添加到文件表 DBFile db = new DBFile(); db.Add(ref fileSvr); //添加到目录表 SqlExec se = new SqlExec(); se.insert("up6_folders", new SqlParam[] { new SqlParam("f_id", id) , new SqlParam("f_pathLoc", fileSvr.pathLoc) , new SqlParam("f_size", fileSvr.sizeLoc) , new SqlParam("f_nameLoc", fileSvr.nameLoc) , new SqlParam("f_pid", pid) , new SqlParam("f_pidRoot", pidRoot) }); up6_biz_event.folder_create(fileSvr); string json = JsonConvert.SerializeObject(fileSvr); json = HttpUtility.UrlEncode(json); json = json.Replace("+", "%20"); var jo = new JObject { { "value", json } }; json = callback + string.Format("({0})", JsonConvert.SerializeObject(jo)); PageTool.to_content(json); }
void file_post() { string uid = Request.Headers["uid"]; string f_id = Request.Headers["id"]; string lenSvr = Request.Headers["lenSvr"]; //已传大小 string lenLoc = Request.Headers["lenLoc"]; //本地文件大小 string blockOffset = Request.Headers["blockOffset"]; string blockSize = Request.Headers["blockSize"]; //当前块大小 string blockIndex = Request.Headers["blockIndex"]; //当前块索引,基于1 string blockMd5 = Request.Headers["blockMd5"]; //块MD5 string complete = Request.Headers["complete"]; //true/false string pathSvr = Request.Form["pathSvr"]; //add(2015-03-19): pathSvr = HttpUtility.UrlDecode(pathSvr); if (this.head_val_null_empty("lenLoc, uid, id, blockOffset")) { return; } if (Request.Files.Count < 1) { PageTool.to_content("file is empty"); return; } bool verify = false; string msg = string.Empty; string md5Svr = string.Empty; HttpPostedFile file = Request.Files.Get(0);//文件块 //计算文件块MD5 if (!string.IsNullOrEmpty(blockMd5)) { md5Svr = Md5Tool.calc(file.InputStream); } //文件块大小验证 verify = int.Parse(blockSize) == file.InputStream.Length; if (!verify) { msg = "block size error sizeSvr:" + file.InputStream.Length + " sizeLoc:" + blockSize; } //块MD5验证 if (verify && !string.IsNullOrEmpty(blockMd5)) { verify = md5Svr == blockMd5; if (!verify) { msg = "block md5 error"; } } if (verify) { //2.0保存文件块数据 FileBlockWriter res = new FileBlockWriter(); res.make(pathSvr, Convert.ToInt64(lenLoc)); res.write(pathSvr, Convert.ToInt64(blockOffset), ref file); up6_biz_event.file_post_block(f_id, Convert.ToInt32(blockIndex)); //生成信息 JObject o = new JObject(); o["msg"] = "ok"; o["md5"] = md5Svr; //文件块MD5 o["offset"] = blockOffset; //偏移 msg = JsonConvert.SerializeObject(o); } PageTool.to_content(msg); }
void file_down() { string id = Request.Headers["id"]; //文件id string blockIndex = Request.Headers["blockIndex"]; //基于1 string blockOffset = Request.Headers["blockOffset"]; //块偏移,相对于整个文件 string blockSize = Request.Headers["blockSize"]; //块大小(当前需要下载的) string pathSvr = Request.Headers["pathSvr"]; //文件在服务器的位置 pathSvr = HttpUtility.UrlDecode(pathSvr); if (this.head_val_null_empty("id, blockIndex, blockOffset, pathSvr")) { Response.StatusCode = 500; var o = this.head_to_json(); PageTool.to_content(o); return; } Response.Clear(); Stream iStream = null; try { // Open the file. iStream = new FileStream(pathSvr, FileMode.Open, FileAccess.Read, FileShare.Read); iStream.Seek(long.Parse(blockOffset), SeekOrigin.Begin);//定位 // Total bytes to read: long dataToRead = long.Parse(blockSize); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Length", blockSize); int buf_size = Math.Min(1048576, int.Parse(blockSize)); byte[] buffer = new Byte[buf_size]; int length; while (dataToRead > 0) { // Verify that the client is connected. if (Response.IsClientConnected) { // Read the data in buffer. length = iStream.Read(buffer, 0, buf_size); dataToRead -= length; // Write the data to the current output stream. Response.OutputStream.Write(buffer, 0, length); // Flush the data to the HTML output. Response.Flush(); } else { //prevent infinite loop if user disconnects dataToRead = -1; } } } catch (Exception ex) { Response.StatusCode = 500; // Trap the error, if any. Response.Write("Error : " + ex.Message); } finally { if (iStream != null) { //Close the file. iStream.Close(); } } }