/// <summary> /// 获取单个指定尺寸图片 /// </summary> /// <param name="request"></param> /// <returns></returns> public object Post(FSScalePicFileRequest request) { int errCode = ImageFileRequestValid(request); if (errCode != (int)FS_ErrorCode.Request_Success) return new AsyncFileDownloadResponse { ret = errCode, message = ErrorCodeDic.GetInstance().CodeMessage(errCode), File_url = null }; AsyncFileDownloadResponse response = new AsyncFileDownloadResponse(); try { IPictureFileService picSvr = new PictureFileService(); response = picSvr.ScalePictureFile(request.file_guid, request.width, request.height); } catch(Exception e) { string err = string.Format("PictureServiceHost.FSScalePicFileRequest error = {0}, request = {1}", e.ToString(), JsonUtil<FSScalePicFileRequest>.ToJson(request)); LogUtil.Error(err); } return response; }
public AsyncFileDownloadResponse ScalePictureFile(string file_guid, int width, int height) { AsyncFileDownloadResponse response = new AsyncFileDownloadResponse(); try { string picGuid = string.Format("{0}_{1}_{2}", file_guid, width, height); string filePath = ScalePictureOperation.GetFileURLFromCache(file_guid, width, height); if (filePath == null) { byte[] bytes = ScalePictureOperation.GetOriginlPicBytes(file_guid); if (bytes == null) { errorCode = (int)FS_ErrorCode.DB_FilePath_Null; response.ret = errorCode; response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode); response.File_url = ""; return response; } FSImageEntity imageEntity = null; using (MemoryStream ms = new MemoryStream()) { ms.Write(bytes, 0, bytes.Length); imageEntity = new FSImageEntity(Image.FromStream(ms), width, height); imageEntity.ConvertSourcePic(); } FileEntity newEntity = ScalePictureOperation.PostNewPicture(picGuid + ".jpg", imageEntity.JpegBytes); IFilePicDA fileDA = FSDbFactory.CreatePicWriteFSDB(); fileDA.InsertNewPicFileRelation(newEntity.file_guid, picGuid, StringUtil.GetDateTimeSeconds(DateTime.Now)); filePath = newEntity.file_path; } Hashtable nginxService = System.Configuration.ConfigurationManager.GetSection("NginxService") as Hashtable; string address = nginxService["Address"].ToString(); if (string.IsNullOrEmpty(filePath)) { errorCode = (int)FS_ErrorCode.DB_FilePath_Null; } response.ret = errorCode; response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode); response.File_url = address + filePath; } catch (Exception ex) { LogUtil.Error(string.Format("Exception FSService.Post(FileDownloadRequest): {0}", ex.ToString())); errorCode = (int)FS_ErrorCode.RequestParam_Err; response.ret = errorCode; response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode); } return response; }
/// <summary> /// 文件通过guid获取存储url地址 /// </summary> /// <param name="request"></param> /// <returns></returns> public object Post(AsyncFileDownloadRequest request) { AsyncFileDownloadResponse response = new AsyncFileDownloadResponse(); try { string guid = request.file_guid; ICommonFilesService filesvr = new CommonFilesService(); response = filesvr.AsynFileDownload(guid); } catch(Exception e) { string err = string.Format("CommonFileServiceHost.AsyncFileDownloadRequest error = {0}, request = {1}", e.ToString(), JsonUtil<AsyncFileDownloadRequest>.ToJson(request)); LogUtil.Error(err); } return response; }
public AsyncFileDownloadResponse AsynFileDownload(string file_guid) { if (string.IsNullOrEmpty(file_guid)) { errorCode = (int)FS_ErrorCode.RequestParam_Err; return new AsyncFileDownloadResponse { ret = errorCode, message = ErrorCodeDic.GetInstance().CodeMessage(errorCode), File_url = "" }; } AsyncFileDownloadResponse response = new AsyncFileDownloadResponse(); try { // 根据FileGuid 查询FilePath ICommonFileRedis Ra = CommonFileRedisFactory.CreateWriteFilesRedis(); string filePath = Ra.GetURLByGuid(file_guid); if (filePath == null) { FileEntity entity = fileDA_R.GetFileEntityByGuid(file_guid); if (entity == null) { errorCode = (int)FS_ErrorCode.DB_FilePath_Null; response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode); return response; } filePath = entity.file_path; ICommonFileRedis RaW = CommonFileRedisFactory.CreateWriteFilesRedis(); RaW.SetCommonFileGuidUrl(file_guid, filePath); } Hashtable nginxService = System.Configuration.ConfigurationManager.GetSection("NginxService") as Hashtable; string address = nginxService["Address"].ToString(); if (string.IsNullOrEmpty(filePath)) { errorCode = (int)FS_ErrorCode.DB_FilePath_Null; } response.ret = errorCode; response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode); response.File_url = address + filePath; LogUtil.Info(string.Format("CommonFilesService.AsynFileDownload {0}",JsonUtil<AsyncFileDownloadResponse>.ToJson(response))); } catch (Exception ex) { LogUtil.Error(string.Format("Exception FSService.Post(FileDownloadRequest): {0}", ex.ToString())); errorCode = (int)FS_ErrorCode.RequestParam_Err; response.ret = errorCode; response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode); } return response; }