diff --git a/Connections/EbConnectionFactory.cs b/Connections/EbConnectionFactory.cs index 6078e2a8..72c87d61 100644 --- a/Connections/EbConnectionFactory.cs +++ b/Connections/EbConnectionFactory.cs @@ -174,6 +174,17 @@ public EbConnectionFactory(string tenantId, IRedisClient redis) InitDatabases(); } + public EbConnectionFactory(ISolutionContext context, IRedisClient redis) + { + this.SolutionId = context.TenantId; + if (string.IsNullOrEmpty(this.SolutionId)) + throw new Exception("Fatal Error :: Solution Id is null or Empty!"); + + this.Redis = redis as RedisClient; + + InitDatabases(); + } + //Call from ServiceStack public EbConnectionFactory(Container c) { diff --git a/Connections/EbConnectionsConfigProvider.cs b/Connections/EbConnectionsConfigProvider.cs index f0895ccb..76ce9229 100644 --- a/Connections/EbConnectionsConfigProvider.cs +++ b/Connections/EbConnectionsConfigProvider.cs @@ -1,4 +1,5 @@ using ExpressBase.Common.Data; +using ExpressBase.Common.Data.AWSS3; using System; using System.Collections.Generic; using System.Text; @@ -151,5 +152,25 @@ public static EbConnectionsConfig DataCenterConnections return _dcConnections; } } + + private static S3 _ebS3Connection = null; + + public static S3 EbS3Connection + { + get + { + if (_ebS3Connection == null) + { + _ebS3Connection = new S3(new EbAWSS3Config + { + BucketName = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_S3_BUCKET_NAME), + BucketRegion = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_S3_BUCKET_REGION), + AccessKeyID = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_S3_ACCESS_KEY_ID), + SecretAccessKey = Environment.GetEnvironmentVariable(EnvironmentConstants.EB_S3_SECRET_ACCESS_KEY) + }); + } + return _ebS3Connection; + } + } } } diff --git a/Connections/HttpSolutionContext.cs b/Connections/HttpSolutionContext.cs new file mode 100644 index 00000000..430b9538 --- /dev/null +++ b/Connections/HttpSolutionContext.cs @@ -0,0 +1,35 @@ +using ExpressBase.Common.Constants; +using Microsoft.AspNetCore.Http; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ExpressBase.Common.Connections +{ + public interface ISolutionContext + { + string TenantId { get; } + } + + public class HttpSolutionContext : ISolutionContext + { + private readonly IHttpContextAccessor _httpContextAccessor; + + public HttpSolutionContext(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + + public string TenantId + { + get + { + var context = _httpContextAccessor.HttpContext; + if (context?.Items.TryGetValue(CoreConstants.SOLUTION_ID, out var tenantId) == true) + return tenantId?.ToString(); + + return CoreConstants.EXPRESSBASE; // default fallback + } + } + } +} diff --git a/Constants/EnvironmentConstants.cs b/Constants/EnvironmentConstants.cs index ebdf2669..ce79f46c 100644 --- a/Constants/EnvironmentConstants.cs +++ b/Constants/EnvironmentConstants.cs @@ -25,6 +25,9 @@ public static class EnvironmentConstants public const string EB_STATICFILESERVER_EXT_URL = "EB_STATICFILESERVER_EXT_URL"; public const string EB_STATICFILESERVER_INT_URL = "EB_STATICFILESERVER_INT_URL"; + public const string EB_STATICFILESERVER2_INT_URL = "EB_STATICFILESERVER2_INT_URL"; + + public const string EB_MQ_URL = "EB_MQ_URL"; //GET ACCESS TOKEN SERVICE URL @@ -116,5 +119,10 @@ public static class EnvironmentConstants public const string MOVEON_AZURE_PNS_CON = "MOVEON_AZURE_PNS_CON"; public const string MOVEON_AZURE_PNS_HUBNAME = "MOVEON_AZURE_PNS_HUBNAME"; public const string EB_API_SECRET = "EB_API_SECRET"; + + public const string EB_S3_BUCKET_NAME = "EB_S3_BUCKET_NAME"; + public const string EB_S3_BUCKET_REGION = "EB_S3_BUCKET_REGION"; + public const string EB_S3_ACCESS_KEY_ID = "EB_S3_ACCESS_KEY_ID"; + public const string EB_S3_SECRET_ACCESS_KEY = "EB_S3_SECRET_ACCESS_KEY"; } } diff --git a/Constants/StaticFileConstants.cs b/Constants/StaticFileConstants.cs index 89579cc1..46ef4157 100644 --- a/Constants/StaticFileConstants.cs +++ b/Constants/StaticFileConstants.cs @@ -1,4 +1,9 @@ -using System.Collections.Generic; +using ExpressBase.Common.EbServiceStack.ReqNRes; +using ExpressBase.Common.Enums; +using ExpressBase.Common.WebApi.RequestNResponse; +using System; +using System.Collections.Generic; +using System.Linq; namespace ExpressBase.Common.Constants { @@ -33,6 +38,7 @@ public static class StaticFileConstants public const string PDFDOWNLOADSUCCESS = "cmd.onPdfDownload"; //Controller Types Url catg strings + public const int MAX_CACHE_SIZE = 256 * 1024; //FileTypes public const string JPG = "jpg"; @@ -52,6 +58,7 @@ public static class StaticFileConstants public const string TXT = "txt"; public const string TEXT = "text"; + public const string CSV = "csv"; public const string PDF = "pdf"; public const string DOC = "doc"; @@ -62,9 +69,8 @@ public static class StaticFileConstants public const string PPT = "ppt"; public const string ZIP = "zip"; - public const string DOTJPG = ".jpg"; - public const string DOTJPEG = ".jepg"; + public const string DOTJPEG = ".jpeg"; public const string DOTPNG = ".png"; public const string DOTBMP = ".bmp"; @@ -72,12 +78,13 @@ public static class StaticFileConstants public const string DOTTXT = ".txt"; public const string DOTTEXT = ".text"; + public const string DOTCSV = ".csv"; public const string DOTPDF = ".pdf"; public const string DOTDOC = ".doc"; public const string DOTDOCX = ".docx"; public const string DOTXLS = ".xls"; - public const string DOTXLSX = ".xxlsx"; + public const string DOTXLSX = ".xlsx"; public const string DOTPPT = ".ppt"; public const string DOTPPTX = ".pptx"; @@ -101,6 +108,7 @@ public static class StaticFileConstants public const string MIME_TXT = "text/plain"; public const string MIME_TEXT = "text/plain"; + public const string MIME_CSV = "text/csv"; public const string MIME_PDF = "application/pdf"; public const string MIME_DOC = "application/msword"; @@ -133,6 +141,7 @@ public static class StaticFileConstants {TXT, MIME_TXT}, {TEXT, MIME_TEXT}, + {CSV, MIME_CSV}, { PDF, MIME_PDF}, {DOC, MIME_DOC}, @@ -162,5 +171,61 @@ public static class StaticFileConstants { M4A,FLAC,MP3,WAVE,WMA,AAC,OPUS }; + + public static string GetMimeType(string fname) + { + var ext = fname.Split('.').LastOrDefault()?.ToLowerInvariant(); + if (ext != null && StaticFileConstants.GetMime.TryGetValue(ext, out string mime)) + { + return mime; + } + return StaticFileConstants.MIME_UNKNOWN; + } + + public static string GetFilePath(dynamic request) + { + EbFileCategory category = (EbFileCategory)request.FileCategory; + + switch (category) + { + case EbFileCategory.Dp: + if (request is UploadDpRequest) + return $"StaticFiles/{request.SolnId}/dp/{request.UserId}.{request.FileType}"; + else + return $"StaticFiles/{request.SolnId}/dp/{request.FileName}.{request.FileType}"; + + case EbFileCategory.File: + return $"StaticFiles/{request.SolnId}/file/{request.FileRefId}.{request.FileType}"; + + case EbFileCategory.Audio: + return $"StaticFiles/{request.SolnId}/{category.ToString().ToLower()}/{request.FileRefId}.{request.FileType}"; + + case EbFileCategory.LocationFile: + return $"StaticFiles/{request.SolnId}/{category.ToString().ToLower()}/{request.FileRefId}.{request.FileType}"; + + case EbFileCategory.Images: + string ImgQuality = ((ImageQuality)request.ImgQuality).ToString(); + + if (request is DownloadFileRequest2) + return $"StaticFiles/{request.SolnId}/{ImgQuality}/{request.FileRefId}.{request.FileType}"; + else + return $"StaticFiles/{request.SolnId}/{ImgQuality}/{request.ImageRefId}.{request.FileType}"; + + case EbFileCategory.SolLogo: + return $"StaticFiles/{request.SolnId}/logo/{request.SolnId}.{request.FileType}"; + + case EbFileCategory.External: + if (request is DownloadWikiImgRequest) + return $"StaticFiles/wiki/{request.RefId}"; + if (request is DownloadInfraImgRequest) + return $"StaticFiles/eb/{request.RefId}"; + if (request is DownloadBotExtImgRequest) + return $"StaticFiles/botExt/{request.RefId}"; + throw new Exception("Unknown external request type"); + + default: + throw new ArgumentOutOfRangeException(nameof(category), $"Unsupported file category: {category}"); + } + } } } diff --git a/Data/AWSS3/S3.cs b/Data/AWSS3/S3.cs new file mode 100644 index 00000000..399ed57b --- /dev/null +++ b/Data/AWSS3/S3.cs @@ -0,0 +1,128 @@ +using Amazon; +using Amazon.S3; +using Amazon.S3.Model; +using Amazon.S3.Transfer; +using ExpressBase.Common.Connections; +using ExpressBase.Common.Constants; +using ExpressBase.Common.Enums; +using ExpressBase.Common.Helpers; +using ServiceStack; +using System; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ExpressBase.Common.Data.AWSS3 +{ + public class S3 : INoSQLDatabase + { + private readonly string bucketName; + private readonly IAmazonS3 s3Client; + public int InfraConId { get; set; } + + public S3(EbAWSS3Config config) + { + InfraConId = config.Id; + bucketName = config.BucketName; + + var region = RegionEndpoint.GetBySystemName(config.BucketRegion); + s3Client = new AmazonS3Client(config.AccessKeyID, config.SecretAccessKey, region); + } + + public string UploadFile(string filename, byte[] bytea, EbFileCategory category) + { + AsyncHelper.RunSync(() => UploadObjectDataAsyncAWSS3(filename, bytea, category)); + return filename; + } + + public string UploadFile2(string filename, byte[] bytea, EbFileCategory category, string s3Path) + { + AsyncHelper.RunSync(() => UploadObjectDataAsyncAWSS3(filename, bytea, category, s3Path)); + return filename; + } + + + + public async Task UploadObjectDataAsyncAWSS3(string filename, byte[] data, EbFileCategory category, string s3Path="") + { + try + { + using (var stream = new MemoryStream(data)) + { + var uploadRequest = new TransferUtilityUploadRequest + { + InputStream = stream, + BucketName = bucketName, + Key = s3Path.TrimStart('/'), + ContentType = StaticFileConstants.GetMimeType(s3Path), + CannedACL = S3CannedACL.Private + }; + + var fileTransferUtility = new TransferUtility(s3Client); + await fileTransferUtility.UploadAsync(uploadRequest); + } + return filename; + } + catch (AmazonS3Exception ex) + { + throw new Exception($"AWS S3 error while uploading '{filename}': {ex.Message}", ex); + } + catch (Exception ex) + { + throw new Exception($"General error while uploading '{filename}': {ex.Message}", ex); + } + } + + public string GetPreSignedUrl(string s3Path, int expiryMinutes = 1) + { + var request = new GetPreSignedUrlRequest + { + BucketName = bucketName, + Key = s3Path, + Expires = DateTime.UtcNow.AddMinutes(expiryMinutes), + Verb = HttpVerb.GET + }; + + return s3Client.GetPreSignedURL(request); + } + + public byte[] DownloadFileById2(string s3Path) + { + return AsyncHelper.RunSync(() => ReadObjectDataAsyncAWSS3( s3Path)); + } + + public byte[] DownloadFileById(string filestoreId, EbFileCategory category) + { + return null;//AsyncHelper.RunSync(() => ReadObjectDataAsyncAWSS3(filestoreId, category)); + } + + public async Task ReadObjectDataAsyncAWSS3(string s3Path = "") + { + try + { + var request = new GetObjectRequest + { + BucketName = bucketName, + Key = s3Path + }; + + using (var response = await s3Client.GetObjectAsync(request)) + using (var memoryStream = new MemoryStream()) + { + await response.ResponseStream.CopyToAsync(memoryStream); + return memoryStream.ToArray(); + } + } + catch (AmazonS3Exception ex) + { + throw new Exception($"AWS S3 error while downloading '{s3Path}': {ex.Message}", ex); + } + catch (Exception ex) + { + throw new Exception($"General error while downloading '{s3Path}': {ex.Message}", ex); + } + } + + } +} diff --git a/Data/IDatabase.cs b/Data/IDatabase.cs index 6049537a..1adfb3d8 100644 --- a/Data/IDatabase.cs +++ b/Data/IDatabase.cs @@ -555,7 +555,7 @@ public virtual string EB_DOWNLOAD_FILE_BY_ID get { return @"SELECT - B.filestore_sid , B.filedb_con_id + B.filestore_sid , B.filedb_con_id, A.filetype FROM eb_files_ref A, eb_files_ref_variations B WHERE @@ -567,7 +567,7 @@ public virtual string EB_DOWNLOAD_IMAGE_BY_ID get { return @"SELECT - B.imagequality_id, B.filestore_sid, B.filedb_con_id + B.imagequality_id, B.filestore_sid, B.filedb_con_id, A.filetype FROM eb_files_ref A, eb_files_ref_variations B WHERE @@ -576,20 +576,52 @@ ORDER BY B.imagequality_id;"; } } + + public virtual string EB_DOWNLOAD_IMAGE_BY_ID2 + { + get + { + return @"SELECT B.imagequality_id, B.filestore_sid, B.filedb_con_id, A.filetype + FROM eb_files_ref A + JOIN eb_files_ref_variations B + ON A.id = B.eb_files_ref_id + WHERE A.id = @fileref + AND (B.imagequality_id = @imagequality_id OR B.imagequality_id = 0) + ORDER BY CASE WHEN B.imagequality_id = @imagequality_id THEN 0 ELSE 1 END + LIMIT 1; "; + } + } + + public virtual string EB_DOWNLOAD_SOLUTION_LOGO + { + get + { + return @"SELECT + filestore_sid , V.filedb_con_id, A.filetype + FROM eb_files_ref A, eb_solutions S, eb_files_ref_variations V + WHERE S.isolution_id = :solid AND V.eb_files_ref_id = S.logorefid AND A.id = V.eb_files_ref_id;"; + } + } + public virtual string EB_DOWNLOAD_DP { get { return @"SELECT - V.filestore_sid , V.filedb_con_id + V.filestore_sid , V.filedb_con_id, A.filetype FROM + eb_files_ref A + INNER JOIN eb_files_ref_variations V + ON + A.id = V.eb_files_ref_id INNER JOIN eb_users U ON V.eb_files_ref_id = U.dprefid WHERE - U.id = @userid"; + U.id = @userid + ORDER BY V.id desc limit 1"; } } public virtual string EB_GET_SELECT_FILE_UPLOADER_CXT diff --git a/Data/INoSQLDatabase.cs b/Data/INoSQLDatabase.cs index 23e3f513..e28b0296 100644 --- a/Data/INoSQLDatabase.cs +++ b/Data/INoSQLDatabase.cs @@ -1,4 +1,8 @@ -using ExpressBase.Common.Enums; +using Amazon; +using ExpressBase.Common.Connections; +using ExpressBase.Common.Data.AWSS3; +using ExpressBase.Common.Enums; +using ExpressBase.Common.LocationNSolution; using System; using System.Collections.Generic; @@ -35,11 +39,14 @@ public class FilesCollection : List public int DefaultConId { get; set; } public int UsedConId { get; set; } - new public INoSQLDatabase this[int _id] { get { + if (_id == 0) + { + return EbConnectionsConfigProvider.EbS3Connection; + } foreach (INoSQLDatabase file in this) { if (file.InfraConId == _id) @@ -51,7 +58,7 @@ public class FilesCollection : List } } - public string UploadFile(string filename, byte[] bytea, EbFileCategory category, int _infraConId) + public string UploadFile(string filename, byte[] bytea, EbFileCategory category, int _infraConId, string s3Path = "", bool isNewFileServer = false) { Console.WriteLine("Inside Upload FilesDB Collection"); @@ -60,7 +67,11 @@ public string UploadFile(string filename, byte[] bytea, EbFileCategory category, try { - if (_infraConId == 0) + if (isNewFileServer) + { + return (this[0] as S3).UploadFile2(filename, bytea, category, s3Path); + } + else if (_infraConId == 0) { _infraConId = DefaultConId; } @@ -76,13 +87,16 @@ public string UploadFile(string filename, byte[] bytea, EbFileCategory category, } - public byte[] DownloadFileById(string filestoreid, EbFileCategory category, int _infraConId) + public string GetPresignedUrl(string s3Path) { - //if (_infraConId == 0) - //{ - // _infraConId = DefaultConId; - //} - //this.UsedConId = _infraConId; + return (this[0] as S3).GetPreSignedUrl(s3Path); + } + + public byte[] DownloadFileById(string filestoreid, EbFileCategory category, int _infraConId, string s3Path = "", bool isNewFileServer = false) + { + if (isNewFileServer && _infraConId == 0) + return (this[0] as S3).DownloadFileById2(s3Path); + if (this[_infraConId + 1000000] != null) return this[_infraConId + 1000000].DownloadFileById(filestoreid, category); diff --git a/ExpressBase.Common.csproj b/ExpressBase.Common.csproj index 126f4093..77a42dc7 100644 --- a/ExpressBase.Common.csproj +++ b/ExpressBase.Common.csproj @@ -51,7 +51,7 @@ - + diff --git a/LocationNSolution/EbLocation.cs b/LocationNSolution/EbLocation.cs index 962eb03e..9f132727 100644 --- a/LocationNSolution/EbLocation.cs +++ b/LocationNSolution/EbLocation.cs @@ -185,6 +185,8 @@ public class SolutionSettings public bool DisbleLeadManagementSave { get; set; } + public bool EnableNewFileServer { get; set; } + public string MaterializedViewDate { get; set; } public List MaterializedViews { get; set; } diff --git a/ServiceClients/EbStaticFileClient2.cs b/ServiceClients/EbStaticFileClient2.cs new file mode 100644 index 00000000..ee1b7fd4 --- /dev/null +++ b/ServiceClients/EbStaticFileClient2.cs @@ -0,0 +1,131 @@ +using ExpressBase.Common; +using ExpressBase.Common.EbServiceStack.ReqNRes; +using ExpressBase.Common.Objects; +using ExpressBase.Common.WebApi.RequestNResponse; +using Microsoft.AspNetCore.Http; +using Newtonsoft.Json; +using SendGrid; +using ServiceStack; +using ServiceStack.Auth; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; + +namespace ExpressBase.Common.ServiceClients +{ + public class EbStaticFileClient2 + { + private readonly HttpClient Client; + + public EbStaticFileClient2(HttpClient client) + { + Client = client; + Client.BaseAddress = new Uri("http://localhost:42800"); + + //_httpClient.BaseAddress = new Uri(Environment.GetEnvironmentVariable(EnvironmentConstants.EB_STATICFILESERVER2_INT_URL)); + } + + public async Task UploadFileAsync(byte[] fileBytes, FileMeta meta, string endpoint, string solutionId, int userId, string userAuthId, int targetUserId = 0) + { + using (var form = new MultipartFormDataContent()) + { + var content = new ByteArrayContent(fileBytes); + content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream"); + form.Add(content, "File", meta.FileName); + + form.Add(new StringContent(meta.Context ?? ""), "Context"); + form.Add(new StringContent(meta.FileType ?? ""), "FileType"); + form.Add(new StringContent(meta.FileName ?? ""), "FileName"); + form.Add(new StringContent(meta.Length.ToString() ?? ""), "Length"); + form.Add(new StringContent(((int)meta.FileCategory).ToString() ?? ""), "FileCategory"); + if (meta is ImageMeta) + form.Add(new StringContent(((int)(meta as ImageMeta).ImageQuality).ToString() ?? ""), "ImageQuality"); + + string metaJson = "{}"; + if (meta.MetaDataDictionary != null && meta.MetaDataDictionary.Count > 0) + { + metaJson = JsonConvert.SerializeObject(meta.MetaDataDictionary); + } + form.Add(new StringContent(metaJson), "MetaData"); + + form.Add(new StringContent(solutionId), "SolnId"); + form.Add(new StringContent(userId.ToString()), "UserId"); + form.Add(new StringContent(userAuthId), "UserAuthId"); + form.Add(new StringContent(targetUserId.ToString() ?? ""), "TargetUserId"); + + + + // Send the request + HttpResponseMessage response = await Client.PostAsync(endpoint.TrimStart('/'), form); + response.EnsureSuccessStatusCode(); + + string responseContent = await response.Content.ReadAsStringAsync(); + + // Use Newtonsoft.Json to deserialize + return JsonConvert.DeserializeObject(responseContent); + } + } + + + public DownloadFileResponse2 DownloadFile(FileMeta meta, string endpoint, string solutionId, int userId = 0, string userAuthId = "_", ImageQuality? imageQuality = null, bool needStreamResult = false) + { + + var query = new Dictionary + { + ["FileRefId"] = meta?.FileRefId.ToString(), + ["FileCategory"] = ((int)meta?.FileCategory).ToString(), + ["SolnId"] = solutionId, + ["UserId"] = userId.ToString(), + ["UserAuthId"] = userAuthId, + ["FileName"] = meta?.FileName ?? " ", + }; + + // Only add ImageQuality if provided + if (imageQuality.HasValue) + { + query["imageQuality"] = ((int)imageQuality).ToString(); + } + query["needStreamResult"] = needStreamResult.ToString().ToLowerInvariant(); + + string queryString = string.Join("&", + query.Select(kvp => $"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value)}")); + + // Ensure proper URL formatting + string url = $"{endpoint.TrimStart('/')}?{queryString}"; + + HttpResponseMessage response = Client.GetAsync(url).GetAwaiter().GetResult(); + response.EnsureSuccessStatusCode(); + + string json = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + DownloadFileResponse2 dfs = JsonConvert.DeserializeObject(json); + return dfs; + } + + public DownloadFileResponse2 DownloadLogo(string solutionId, bool needStreamResult = false) + { + string endpoint = "download/logo"; + var query = new Dictionary + { + ["SolnId"] = solutionId, + ["needStreamResult"] = needStreamResult.ToString().ToLowerInvariant() + }; + string queryString = string.Join("&", + query.Select(kvp => $"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value)}")); + + // Ensure proper URL formatting + string url = $"{endpoint}?{queryString}"; + + HttpResponseMessage response = Client.GetAsync(url).GetAwaiter().GetResult(); + response.EnsureSuccessStatusCode(); + + string json = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + DownloadFileResponse2 dfs = JsonConvert.DeserializeObject(json); + return dfs; + } + + } +} diff --git a/ServiceStack/ReqNRes/FileService_Artifacts.cs b/ServiceStack/ReqNRes/FileService_Artifacts.cs index 06f8d977..a4e22d1b 100644 --- a/ServiceStack/ReqNRes/FileService_Artifacts.cs +++ b/ServiceStack/ReqNRes/FileService_Artifacts.cs @@ -35,6 +35,9 @@ public class UploadFileRequest : EbMqRequest, IReturn [DataMember(Order = 5)] public string SubscriptionId { get; set; } + + [DataMember(Order = 6)] + public string FileType { get; set; } } [DataContract] @@ -72,6 +75,9 @@ public interface IUploadImageRequest string SolutionId { get; set; } string SubscriptionId { get; set; } + + string FileType { get; set; } + } [DataContract] @@ -119,6 +125,9 @@ public class UploadImageRequest : IReturn, IUploadImageRequest [DataMember(Order = 14)] public string SubscriptionId { get; set; } + [DataMember(Order = 15)] + public string FileType { get; set; } + } [DataContract] @@ -166,6 +175,9 @@ public class UploadImageInfraMqRequest : IReturn, IUploadImageRequ [DataMember(Order = 14)] public string SubscriptionId { get; set; } + [DataMember(Order = 15)] + public string FileType { get; set; } + } [DataContract] @@ -213,6 +225,10 @@ public class UploadDpRequest : IReturn, IUploadImageRequest [DataMember(Order = 14)] public string SubscriptionId { get; set; } + [DataMember(Order = 15)] + public string FileType { get; set; } + + } [DataContract] @@ -259,6 +275,9 @@ public class UploadLogoRequest : IReturn, IUploadImageRequest [DataMember(Order = 14)] public string SubscriptionId { get; set; } + + [DataMember(Order = 15)] + public string FileType { get; set; } } [DataContract] public class UploadLocRequest : IReturn, IUploadImageRequest @@ -304,6 +323,9 @@ public class UploadLocRequest : IReturn, IUploadImageRequest [DataMember(Order = 14)] public string SubscriptionId { get; set; } + + [DataMember(Order = 15)] + public string FileType { get; set; } } [DataContract] @@ -368,44 +390,10 @@ public class FileMeta } [DataContract] - public class ImageMeta + public class ImageMeta : FileMeta { - [DataMember(Order = 1)] - public string FileStoreId { get; set; } - - [DataMember(Order = 2)] - public Int32 FileRefId { get; set; } - - - [DataMember(Order = 3)] - public string FileName { get; set; } - - [DataMember(Order = 4)] - public IDictionary> MetaDataDictionary { get; set; } - - [DataMember(Order = 5)] - public DateTime UploadDateTime { get; set; } - - [DataMember(Order = 6)] - public Int64 Length { get; set; } - - [DataMember(Order = 7)] - public string FileType { get; set; } - - [DataMember(Order = 8)] - public EbFileCategory FileCategory { get; set; } - - [DataMember(Order = 9)] - public ImageQuality ImageQuality { get; set; } - - [DataMember(Order = 10)] - public int ImgManipulationServiceId { get; set; } - - [DataMember(Order = 11)] - public int InfraConID { get; set; } - [DataMember(Order = 12)] - public string Context { get; set; } + public ImageQuality ImageQuality { get; set; } } [DataContract] @@ -634,12 +622,12 @@ public class DownloadFileByIdRequest : EbServiceStackAuthRequest, IReturn - { - [DataMember(Order = 1)] - public FileMeta FileDetails { get; set; } - } + //[DataContract] + //public class DownloadFileByRefIdRequest : EbServiceStackAuthRequest, IReturn + //{ + // [DataMember(Order = 1)] + // public FileMeta FileDetails { get; set; } + //} //[DataContract] //public class EbFileId diff --git a/WebApi/RequestNResponse/FileServiceArtifacts.cs b/WebApi/RequestNResponse/FileServiceArtifacts.cs new file mode 100644 index 00000000..5ded5351 --- /dev/null +++ b/WebApi/RequestNResponse/FileServiceArtifacts.cs @@ -0,0 +1,104 @@ + +using ExpressBase.Common.EbServiceStack.ReqNRes; +using ExpressBase.Common.Enums; +using Microsoft.AspNetCore.Http; +using Newtonsoft.Json; +using ServiceStack; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.IO; +using System.Runtime.Serialization; +using System.Text; + +namespace ExpressBase.Common.WebApi.RequestNResponse +{ + public class UploadFileRequest2 + { + public IFormFile File { get; set; } + + public string Context { get; set; } + + public string FileType { get; set; } + + public string FileName { get; set; } + + public long Length { get; set; } + + public int FileCategory { get; set; } + + public int ImageQuality { get; set; } + + public string MetaData { get; set; } + + public string SolnId { get; set; } + + public int UserId { get; set; } + + public string UserAuthId { get; set; } + + public int TargetUserId { get; set; } + } + + public class DownloadFileRequest2 + { + public int FileRefId { get; set; } + + public int FileCategory { get; set; } + + public int ImgQuality { get; set; } + + public string FileName { get; set; } + + public string SolnId { get; set; } + + public int UserId { get; set; } + + public string UserAuthId { get; set; } + + public string FileType { get; set; } + + public bool NeedStreamResult { get; set; } + + } + + + public class DownloadFileResponse2 + { + [DataMember(Order = 1)] + public FileMeta FileDetails { get; set; } + + [DataMember(Order = 2)] + public byte[] FileBytes { get; set; } + + [DataMember(Order = 3)] + public ResponseStatus ResponseStatus { get; set; } + + [DataMember(Order = 4)] + public string PreSignedUrl { get; set; } + } + + public class UploadImageAsyncRequest2 + { + public ImageMeta ImageInfo { get; set; } + + public byte[] ImageByte { get; set; } + + public string SolutionId { get; set; } + + public int UserIntId { get; set; } + } + + public class UploadAsyncResponse2 + { + public int FileRefId { get; set; } + + public ResponseStatus ResponseStatus { get; set; } + } + + public class ResponseStatus + { + public string Message { get; set; } + } +}