public override async Task <string> SaveAsync(FileProviderSaveArgs args)
        {
            var filePath = FilePathCalculator.Calculate(args);

            if (!args.OverrideExisting && await ExistsAsync(filePath))
            {
                throw new FileAlreadyExistsException($"Saving File '{args.FileId}' does already exists in the container '{args.ContainerName}'! Set {nameof(args.OverrideExisting)} if it should be overwritten.");
            }

            DirectoryHelper.CreateIfNotExists(Path.GetDirectoryName(filePath));

            var fileMode = args.OverrideExisting
                ? FileMode.Create
                : FileMode.CreateNew;

            await Policy.Handle <IOException>()
            .WaitAndRetryAsync(2, retryCount => TimeSpan.FromSeconds(retryCount))
            .ExecuteAsync(async() =>
            {
                using var fileStream = File.Open(filePath, fileMode, FileAccess.Write);
                await args.FileStream.CopyToAsync(
                    fileStream,
                    args.CancellationToken
                    );

                await fileStream.FlushAsync();
            });

            return(filePath);
        }
Exemple #2
0
        public override async Task <string> SaveAsync(FileProviderSaveArgs args)
        {
            var fileName      = S3FileNameCalculator.Calculate(args);
            var configuration = args.Configuration.GetS3Configuration();
            var client        = GetS3Client(args);
            var containerName = GetContainerName(args);

            if (!args.OverrideExisting && await FileExistsAsync(client, containerName, fileName, args.CancellationToken))
            {
                throw new FileAlreadyExistsException($"Saving File '{args.FileId}' does already exists in the container '{containerName}'! Set {nameof(args.OverrideExisting)} if it should be overwritten.");
            }

            if (configuration.CreateBucketIfNotExists)
            {
                await CreateBucketIfNotExists(client, containerName);
            }

            if (configuration.EnableSlice && (args.FileStream.Length > configuration.SliceSize))
            {
                await MultipartUploadInternal(client, containerName, fileName, args.FileStream, configuration.UseChunkEncoding, configuration.SliceSize);
            }
            else
            {
                await SingleUploadInternal(client, containerName, fileName, args.FileStream, configuration.UseChunkEncoding);
            }

            args.FileStream?.Dispose();

            return(fileName);
        }
Exemple #3
0
        public override async Task <string> SaveAsync(FileProviderSaveArgs args)
        {
            var container = await GetOrCreateContainerAsync(args.ContainerName, args.CancellationToken);

            var file = await DatabaseFileRepository.FindAsync(
                container.Id,
                args.ContainerName,
                args.CancellationToken
                );

            var content = await args.FileStream.GetAllBytesAsync(args.CancellationToken);

            if (file != null)
            {
                if (!args.OverrideExisting)
                {
                    throw new FileAlreadyExistsException(
                              $"Saving File '{args.FileId}' does already exists in the container '{args.ContainerName}'! Set {nameof(args.OverrideExisting)} if it should be overwritten.");
                }

                file.SetContent(content);

                await DatabaseFileRepository.UpdateAsync(file, autoSave : true);
            }
            else
            {
                file = new DatabaseFile(GuidGenerator.Create(), container.Id, args.FileId, content, CurrentTenant.Id);
                await DatabaseFileRepository.InsertAsync(file, autoSave : true);
            }

            return(args.FileId);
        }
        public override async Task <string> SaveAsync(FileProviderSaveArgs args)
        {
            var configuration = args.Configuration.GetFastDFSConfiguration();

            ConfigurationFactory.AddIfNotContains(configuration);

            var containerName = GetContainerName(configuration, args);
            var storageNode   = await Client.GetStorageNodeAsync(containerName, configuration.ClusterName);

            var fileId = await Client.UploadFileAsync(storageNode, args.FileStream, args.FileExt, configuration.ClusterName);

            return(fileId);
        }
Exemple #5
0
        public override async Task <string> SaveAsync(FileProviderSaveArgs args)
        {
            var fileName      = AzureFileNameCalculator.Calculate(args);
            var configuration = args.Configuration.GetAzureConfiguration();

            if (!args.OverrideExisting && await FileExistsAsync(args, fileName))
            {
                throw new FileAlreadyExistsException($"Saving File '{args.FileId}' does already exists in the container '{GetContainerName(args)}'! Set {nameof(args.OverrideExisting)} if it should be overwritten.");
            }

            if (configuration.CreateContainerIfNotExists)
            {
                await CreateContainerIfNotExists(args);
            }

            await GetBlobClient(args, fileName).UploadAsync(args.FileStream, true);

            return(fileName);
        }
Exemple #6
0
        public override async Task <string> SaveAsync(FileProviderSaveArgs args)
        {
            var fileName      = MinioFileNameCalculator.Calculate(args);
            var configuration = args.Configuration.GetMinioConfiguration();
            var client        = GetMinioClient(args);
            var containerName = GetContainerName(args);

            if (!args.OverrideExisting && await FileExistsAsync(client, containerName, fileName))
            {
                throw new FileAlreadyExistsException($"Saving File '{args.FileId}' does already exists in the container '{containerName}'! Set {nameof(args.OverrideExisting)} if it should be overwritten.");
            }

            if (configuration.CreateBucketIfNotExists)
            {
                await CreateBucketIfNotExists(client, containerName);
            }

            await client.PutObjectAsync(containerName, fileName, args.FileStream, args.FileStream.Length);

            return(args.FileId);
        }
        public override Task <string> SaveAsync(FileProviderSaveArgs args)
        {
            var containerName = GetContainerName(args);
            var fileName      = AliyunFileNameCalculator.Calculate(args);
            var aliyunConfig  = args.Configuration.GetAliyunConfiguration();
            var ossClient     = GetOssClient(aliyunConfig);

            if (!args.OverrideExisting && FileExistsAsync(ossClient, containerName, fileName))
            {
                throw new FileAlreadyExistsException($"Saving FILE '{args.FileId}' does already exists in the container '{containerName}'! Set {nameof(args.OverrideExisting)} if it should be overwritten.");
            }
            if (aliyunConfig.CreateContainerIfNotExists)
            {
                if (!ossClient.DoesBucketExist(containerName))
                {
                    ossClient.CreateBucket(containerName);
                }
            }

            ossClient.PutObject(containerName, fileName, args.FileStream);
            return(Task.FromResult(fileName));
        }
Exemple #8
0
 public Task <string> SaveAsync(FileProviderSaveArgs args)
 {
     throw new NotImplementedException();
 }