public class Biz_UploadImage : Biz_UploadImageBase { /// <summary> /// 上传图片接口 /// </summary> /// <param name="uploadImageData"></param> /// <returns></returns> public dataresult UploadImageInterface(Stream uploadImageData, string ip) { try { var sr = new StreamReader(uploadImageData); string str = sr.ReadToEnd(); WriteLogHelper wlHelper = new WriteLogHelper(); wlHelper.WriteToFile(DateTime.Now.ToString()); wlHelper.WriteToFile(string.Format("UploadImageInterface_str:{0}", str)); wlHelper.WriteToFile(" "); JsonUploadImageData json = JsonHelper.Deserialize<JsonUploadImageData>(str); json.remark = Decode(json.remark); json.operate_name = Decode(json.operate_name); return UploadImageInterface(json, ip); } catch { return return_CustomError("Json格式错误!"); ; } } /// <summary> /// 缩略图 /// </summary> /// <param name="uploadThumbnailImageData"></param> /// <returns></returns> public dataresult UploadThumbnailInterface(Stream uploadThumbnailImageData, string ip) { try { var sr = new StreamReader(uploadThumbnailImageData); string str = sr.ReadToEnd(); WriteLogHelper wlHelper = new WriteLogHelper(); wlHelper.WriteToFile(DateTime.Now.ToString()); wlHelper.WriteToFile(string.Format("UploadThumbnailInterface_str:{0}", str)); wlHelper.WriteToFile(" "); JsonUploadThumbnailImageData json = JsonHelper.Deserialize<JsonUploadThumbnailImageData>(str); json.remark = Decode(json.remark); json.operate_name = Decode(json.operate_name); json.file_path = Decode(json.file_path); return UploadThumbnailInterface(json, ip); } catch { return return_CustomError("Json格式错误!"); ; } } public dataresult UnBoxingJson(Stream dataStream, bool isThumbnail) { return null; } /// <summary> /// 缩略图 /// </summary> /// <param name="json"></param> /// <returns></returns> protected dataresult UploadThumbnailInterface(JsonUploadThumbnailImageData json, string ip) { dataresult dr = new dataresult(); try { if (!VerifySign(json)) return return_CustomError("验证不通过!"); string readFile = ConfigHelper.UserImg_filePath + json.file_path; if (!File.Exists(readFile.Replace("/", @"\"))) return return_CustomError("指定要压缩的图片不存在!"); //生产路径 PackagingPathEntity pathEntity = PathGenerator(json,readFile); //List<ReturnUrlPathEntity> returnList = new List<ReturnUrlPathEntity>(); string pathAndName = dal.IsExistmoto_img(json.img_code); //List<string> loopFile = LoopReadFile(readFile); //foreach (var item in loopFile) //{ //压缩图片并保存图片 //bool isThumbnailOk = ImageHelper.GetPicThumbnail(string.Format(@"{0}\{1}", readFile, item), pathEntity.AbsolutePath, item, json.h, json.w, 100); bool isThumbnailOk = ImageHelper.GetPicThumbnail(readFile.Replace("/", @"\"), pathEntity.AbsolutePath, pathEntity.FileName, json.h, json.w, 100); if (!isThumbnailOk) return return_CustomError("保存图片失败!"); //图片唯一标示,该code在表中存在则删除原文件再创建 if (File.Exists(ConfigHelper.UserImg_filePath + pathAndName)) File.Delete(ConfigHelper.UserImg_filePath + pathAndName); ReturnUrlPathEntity returnUrlPath = SaveInDatabase(json, pathEntity.RelativePath, pathEntity.FileName, ip, pathAndName); //if (returnUrlPath != null) // returnList.Add(returnUrlPath); //} dr.data = returnUrlPath; dr.code = "1"; dr.msg = "succ"; return dr; } catch (Exception ex) { dr.code = "-1"; dr.msg = ex.Message; } return dr; } /// <summary> /// 上传图片接口 /// </summary> /// <param name="json"></param> /// <param name="ip"></param> /// <returns></returns> protected dataresult UploadImageInterface(JsonUploadImageData json, string ip) { dataresult dr = new dataresult(); try { if (!VerifySign(json)) return return_CustomError("验证不通过!"); //生产路径 PackagingPathEntity pathEntity = PathGenerator(json); string pathAndName = dal.IsExistmoto_img(json.img_code); //保存图片 string relativePath = SaveImageInFile(pathEntity, Convert.FromBase64String(json.image_data), pathAndName); if (string.IsNullOrEmpty(relativePath)) return return_CustomError("保存图片失败!"); //List<ReturnUrlPathEntity> returnList = new List<ReturnUrlPathEntity>(); ReturnUrlPathEntity returnUrlPath = SaveInDatabase(json, relativePath, pathEntity.FileName, ip, pathAndName); //if (returnUrlPath != null) // returnList.Add(returnUrlPath); dr.data = returnUrlPath; dr.code = "1"; dr.msg = "succ"; return dr; } catch (Exception ex) { dr.code = "-1"; dr.msg = ex.Message; } return dr; } }