/// <summary>
        /// Internals the save.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        protected override FileStorageResultDTO InternalSave(FileArgs args)
        {
            var targetRelativePathElements = args.GetRelativePathElements();
            var targetFileNameElements     = args.GetFileNameElements();

            var rootPath   = args.TargetRootPath ?? FileSystemStorage.FileSystemBaseStoragePath;
            var folderPath = (args.BuildRelativePath ?? this.BuildRelativePath)(targetRelativePathElements);
            var fileName   = (args.BuildFileName ?? this.BuildFileName)(targetFileNameElements);

            fileName += Path.GetExtension(args.UploadedFile.OriginalFileName);

            var directoryPath    = Path.Combine(rootPath, folderPath);
            var relativeFilePath = Path.Combine(folderPath, fileName);

            try
            {
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                var filePath = Path.Combine(directoryPath, fileName);

                using (var fileStream = File.OpenWrite(filePath))
                {
                    using (var streamWriter = new BinaryWriter(fileStream))
                    {
                        streamWriter.Write(args.FileContent);
                    }
                }

                var result = new FileStorageResultDTO
                {
                    RootPath     = rootPath,
                    AccessPath   = null,
                    FolderPath   = folderPath,
                    FileName     = fileName,
                    FileSourceId = Identifier
                };

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Internals the save.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        protected override FileStorageResultDTO InternalSave(FileArgs args)
        {
            string[] targetRelativePathElements = args.GetRelativePathElements();
            string[] targetFileNameElements     = args.GetFileNameElements();

            var relativePath = (args.BuildRelativePath ?? this.BuildRelativePath)(targetRelativePathElements);
            var fileName     = (args.BuildFileName ?? this.BuildFileName)(targetFileNameElements);

            fileName += Path.GetExtension(args.UploadedFile.OriginalFileName);

            string FullFileKey = string.Join("/", relativePath, fileName);// Path.Combine(relativePath, fileName);

            try
            {
                using (var client = this.CreateClient(AWSStorage.AWSFileStoreRootURL))
                {
                    AWSUploadPublicFileAsync(client, args.UploadedFile.FileContent, AWSStorage.AWSFileRepoBucketName /* ConfigurationManager.AppSettings["AWSFileRepoBucketName"]*/, FullFileKey).Wait();
                }

                var result = new FileStorageResultDTO
                {
                    RootPath     = AWSStorage.AWSFileStoreRootURL,
                    AccessPath   = AWSStorage.AWSFileRepoBucketName,
                    FolderPath   = relativePath,
                    FileName     = fileName,
                    FileSourceId = Identifier
                };

                return(result);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"AWSStorage.InternalSave ERROR - [{ex.Message}]");
                throw;
            }
        }
Example #3
0
        /// <summary>
        /// Internals the save.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        protected override FileStorageResultDTO InternalSave <T>(FileArgs <T> args)
        {
            var targetRelativePathElements = args.GetRelativePathElements();
            var targetFileNameElements     = args.GetFileNameElements();

            var rootPath   = args.TargetRootPath ?? FileSystemStorage.FileSystemBaseStoragePath;
            var folderPath = (args.BuildRelativePath ?? this.BuildRelativePath)(targetRelativePathElements);
            var fileName   = (args.BuildFileName ?? this.BuildFileName)(targetFileNameElements);

            fileName += Path.GetExtension(args.UploadedFile.OriginalFileName);

            var    directoryPath    = Path.Combine(rootPath, folderPath);
            var    relativeFilePath = Path.Combine(folderPath, fileName);
            string thumbnailFileNameWithExtension = null;

            try
            {
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                var filePath = Path.Combine(directoryPath, fileName);

                using (var fileStream = File.OpenWrite(filePath))
                {
                    using (var streamWriter = new BinaryWriter(fileStream))
                    {
                        streamWriter.Write(args.FileContent);
                    }
                }


                string thumbnailFilePath = null;
                if (args.UploadedFile.ThumbnailContent != null && args.UploadedFile.ThumbnailContent.Length > 0)
                {
                    // main file name construction
                    var thumbnailFileName = $"{fileName}_thumbnail";
                    thumbnailFileNameWithExtension = thumbnailFileName + ".png";
                    thumbnailFilePath = Path.Combine(directoryPath, thumbnailFileNameWithExtension);

                    using (var fileStream = File.OpenWrite(thumbnailFilePath))
                    {
                        using (var streamWriter = new BinaryWriter(fileStream))
                        {
                            streamWriter.Write(args.UploadedFile.ThumbnailContent);
                        }
                    }
                }

                var result = new FileStorageResultDTO
                {
                    RootPath              = rootPath,
                    AccessPath            = null,
                    FolderPath            = folderPath,
                    FileName              = fileName,
                    ThumbnailFileName     = thumbnailFileNameWithExtension,
                    FileSourceId          = Identifier,
                    FullFilePath          = filePath,
                    ThumbnailFullFilePath = thumbnailFilePath
                };

                return(result);
            }
            catch (Exception ex)
            {
                this.Logger.Error("Error saving uploaded file", ex);
                throw ex;
            }
        }