/// <summary> /// 抓取远程图片 /// </summary> public ActionResult catchimage() { Code.SysConfig.sysconfig sysConfig = new Code.SysConfig.SysConfigApp().loadConfig(); if (sysConfig.fileremote == 0) { return(showError("未开启远程图片本地化")); } string[] sourcesUriArr = Request.Form.GetValues("source[]"); if (sourcesUriArr == null || sourcesUriArr.Length == 0) { return(showError("参数错误:没有指定抓取源")); } UpLoad upLoad = new UpLoad(); //初始化上传类 List <Hashtable> fileList = new List <Hashtable>(); //存储上传成功的文件列表 foreach (string sourcesUri in sourcesUriArr) { string remsg = upLoad.RemoteSaveAs(sourcesUri); Dictionary <string, object> dic = JsonHelper.DataRowFromJSON(remsg); //如果抓取成功则加入文件列表 if (dic["status"].ToString() == "1") { Hashtable hash = new Hashtable(); hash["state"] = "SUCCESS"; hash["source"] = sourcesUri; hash["url"] = dic["path"].ToString(); fileList.Add(hash); } } Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("state", "SUCCESS"); result.Add("list", fileList); return(Content(result.ToJson())); }
/// <summary> /// 抓取远程图片 /// </summary> private void EditorCatchImage(HttpContext context) { Model.sysconfig sysConfig = new BLL.sysconfig().loadConfig(); if (sysConfig.fileremote == 0) { Hashtable hash = new Hashtable(); hash["state"] = "未开启远程图片本地化"; context.Response.AddHeader("Content-Type", "text/plain; charset=UTF-8"); context.Response.Write(JsonHelper.ObjectToJSON(hash)); context.Response.End(); } string[] sourcesUriArr = context.Request.Form.GetValues("source[]"); if (sourcesUriArr == null || sourcesUriArr.Length == 0) { Hashtable hash = new Hashtable(); hash["state"] = "参数错误:没有指定抓取源"; context.Response.AddHeader("Content-Type", "text/plain; charset=UTF-8"); context.Response.Write(JsonHelper.ObjectToJSON(hash)); context.Response.End(); } UpLoad upLoad = new UpLoad(); //初始化上传类 List <Hashtable> fileList = new List <Hashtable>(); //存储上传成功的文件列表 foreach (string sourcesUri in sourcesUriArr) { string remsg = upLoad.RemoteSaveAs(sourcesUri); Dictionary <string, object> dic = JsonHelper.DataRowFromJSON(remsg); //如果抓取成功则加入文件列表 if (dic["status"].ToString() == "1") { Hashtable hash = new Hashtable(); hash["state"] = "SUCCESS"; hash["source"] = sourcesUri; hash["url"] = dic["path"].ToString(); fileList.Add(hash); } } Hashtable result = new Hashtable(); result["state"] = "SUCCESS"; result["list"] = fileList; context.Response.AddHeader("Content-Type", "text/plain; charset=UTF-8"); context.Response.Write(JsonHelper.ObjectToJSON(result)); context.Response.End(); }