public void UploadObjectInGoogleStorage(string fileName, int inMemoryCachyExpireDays, string objectName, string bucketName, object anonymousDataObject, string contentType, string CACHE_KEY) { string content = _fileReadService.FileAsString(fileName, inMemoryCachyExpireDays, CACHE_KEY); content = _fileReadService.FillContent(content, anonymousDataObject); Stream stream = _fileReadService.FileAsStream(content); _googleStorage.UploadObject(bucketName, stream, objectName, contentType); }
private void UploadObjectInGoogleStorage(GoogleStorageArticleFileDto model) { if (model == null) { throw new ArgumentNullException(nameof(GoogleStorageArticleFileDto)); } if (model.ArticleAnonymousDataObjectForHtmlTemplate == null) { throw new ArgumentNullException(nameof(model.ArticleAnonymousDataObjectForHtmlTemplate)); } string content = _cacheService.Get <string>(model.CACHE_KEY); if (string.IsNullOrWhiteSpace(content)) { content = System.IO.File.ReadAllText(model.HtmlFileTemplateFullPathWithExt); if (string.IsNullOrEmpty(content)) { throw new Exception(nameof(content)); } content = _cacheService.GetOrAdd <string>(model.CACHE_KEY, () => content, model.CacheExpiryDateTimeForHtmlTemplate); if (string.IsNullOrEmpty(content)) { throw new Exception(nameof(content)); } } content = _fileReadService.FillContent(content, model.ArticleAnonymousDataObjectForHtmlTemplate); if (string.IsNullOrEmpty(content)) { throw new Exception(nameof(content)); } Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(content)); if (stream == null || stream.Length <= 0) { throw new Exception(nameof(stream)); } _googleStorage.UploadObject(model.GoogleStorageBucketName, stream, model.GoogleStorageObjectNameWithExt, model.ContentType); }