Exemplo n.º 1
0
        public override async Task <Stream> GetOrNullAsync(FileProviderGetArgs args)
        {
            var fileName      = MinioFileNameCalculator.Calculate(args);
            var client        = GetMinioClient(args);
            var containerName = GetContainerName(args);

            if (!await FileExistsAsync(client, containerName, fileName))
            {
                return(null);
            }

            var memoryStream = new MemoryStream();
            await client.GetObjectAsync(containerName, fileName, async stream =>
            {
                if (stream != null)
                {
                    await stream.CopyToAsync(memoryStream);
                }
                else
                {
                    memoryStream = null;
                }
            });

            return(memoryStream);
        }
Exemplo n.º 2
0
        public override async Task <bool> ExistsAsync(FileProviderExistsArgs args)
        {
            var fileName      = MinioFileNameCalculator.Calculate(args);
            var client        = GetMinioClient(args);
            var containerName = GetContainerName(args);

            return(await FileExistsAsync(client, containerName, fileName));
        }
Exemplo n.º 3
0
        public override async Task <bool> DeleteAsync(FileProviderDeleteArgs args)
        {
            var fileName      = MinioFileNameCalculator.Calculate(args);
            var client        = GetMinioClient(args);
            var containerName = GetContainerName(args);

            if (await FileExistsAsync(client, containerName, fileName))
            {
                await client.RemoveObjectAsync(containerName, fileName);

                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public override async Task <bool> DownloadAsync(FileProviderDownloadArgs args)
        {
            var fileName      = MinioFileNameCalculator.Calculate(args);
            var client        = GetMinioClient(args);
            var containerName = GetContainerName(args);

            if (!await FileExistsAsync(client, containerName, fileName))
            {
                return(false);
            }

            await client.GetObjectAsync(containerName, fileName, args.Path);

            return(true);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public override async Task <string> GetAccessUrlAsync(FileProviderAccessArgs args)
        {
            if (!args.Configuration.HttpAccess)
            {
                return(string.Empty);
            }

            var fileName      = MinioFileNameCalculator.Calculate(args);
            var client        = GetMinioClient(args);
            var containerName = GetContainerName(args);

            if (!await FileExistsAsync(client, containerName, fileName))
            {
                return(string.Empty);
            }

            var expiresInt = 600;

            if (args.Expires.HasValue && args.Expires > Clock.Now)
            {
                expiresInt = Convert.ToInt32((args.Expires.Value - Clock.Now).TotalSeconds);
            }
            return(await client.PresignedGetObjectAsync(containerName, fileName, expiresInt));
        }