public string Post(ImageResizeMqRequest request) { UploadFileMqRequest uploadFileRequest = new UploadFileMqRequest(); uploadFileRequest.TenantAccountId = request.TenantAccountId; uploadFileRequest.UserId = request.UserId; MemoryStream ms = new MemoryStream(request.ImageByte); ms.Position = 0; try { using (Image img = Image.FromStream(ms)) { if (request.ImageInfo.FileName.StartsWith("dp")) { foreach (string size in Enum.GetNames(typeof(DPSizes))) { Stream ImgStream = Resize(img, (int)((DPSizes)Enum.Parse(typeof(DPSizes), size)), (int)((DPSizes)Enum.Parse(typeof(DPSizes), size))); request.ImageByte = new byte[ImgStream.Length]; ImgStream.Read(request.ImageByte, 0, request.ImageByte.Length); uploadFileRequest.FileByte = request.ImageByte; uploadFileRequest.BucketName = "dp_images"; uploadFileRequest.FileDetails = new FileMeta() { FileName = request.ImageInfo.FileName, MetaDataDictionary = (request.ImageInfo.MetaDataDictionary != null) ? request.ImageInfo.MetaDataDictionary : new Dictionary <String, List <string> >() { }, FileType = request.ImageInfo.FileType }; this.MessageProducer3.Publish(uploadFileRequest); } } else { foreach (string size in Enum.GetNames(typeof(ImageSizes))) { Stream ImgStream = Resize(img, (int)((ImageSizes)Enum.Parse(typeof(ImageSizes), size)), (int)((ImageSizes)Enum.Parse(typeof(ImageSizes), size))); request.ImageByte = new byte[ImgStream.Length]; ImgStream.Read(request.ImageByte, 0, request.ImageByte.Length); uploadFileRequest.FileDetails = new FileMeta() { FileName = request.ImageInfo.ObjectId + "_" + size + ".png", MetaDataDictionary = (request.ImageInfo.MetaDataDictionary != null) ? request.ImageInfo.MetaDataDictionary : new Dictionary <String, List <string> >() { }, FileType = "png" }; uploadFileRequest.FileByte = request.ImageByte; uploadFileRequest.BucketName = string.Format("images_{0}", size); this.MessageProducer3.Publish(uploadFileRequest); } } } } catch (Exception e) { } return(null); }
public string Post(UploadFileMqRequest request) { try { string Id = (new TenantDbFactory(request.TenantAccountId, this.Redis)).FilesDB.UploadFile( request.FileDetails.FileName, (request.FileDetails.MetaDataDictionary.Count != 0) ? request.FileDetails.MetaDataDictionary : new Dictionary <String, List <string> >() { }, request.FileByte, request.BucketName ). ToString(); this.MessageProducer3.Publish(new FileMetaPersistMqRequest { FileDetails = new FileMeta { ObjectId = Id, FileName = request.FileDetails.FileName, MetaDataDictionary = (request.FileDetails.MetaDataDictionary != null) ? request.FileDetails.MetaDataDictionary : new Dictionary <String, List <string> >() { }, Length = request.FileByte.Length, FileType = request.FileDetails.FileType }, BucketName = request.BucketName, TenantAccountId = request.TenantAccountId, UserId = request.UserId }); if (request.BucketName == "images_original" || (request.BucketName == "dp_images" && request.FileDetails.FileName.Split('_').Length == 2)) { this.MessageProducer3.Publish(new ImageResizeMqRequest { ImageInfo = new FileMeta { ObjectId = Id, FileName = request.FileDetails.FileName, MetaDataDictionary = (request.FileDetails.MetaDataDictionary != null) ? request.FileDetails.MetaDataDictionary : new Dictionary <String, List <string> >() { } }, ImageByte = request.FileByte, TenantAccountId = request.TenantAccountId, UserId = request.UserId }); } else { return(null); } } catch (Exception e) { } return(null); }