Beispiel #1
0
    public override async Task <Stream> GetOrNullAsync(BlobProviderGetArgs args)
    {
        var blobName      = MinioBlobNameCalculator.Calculate(args);
        var client        = GetMinioClient(args);
        var containerName = GetContainerName(args);

        if (!await BlobExistsAsync(client, containerName, blobName))
        {
            return(null);
        }

        var memoryStream = new MemoryStream();
        await client.GetObjectAsync(containerName, blobName, (stream) =>
        {
            if (stream != null)
            {
                stream.CopyTo(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
            }
            else
            {
                memoryStream = null;
            }
        });

        return(memoryStream);
    }
Beispiel #2
0
    public override async Task <bool> ExistsAsync(BlobProviderExistsArgs args)
    {
        var blobName      = MinioBlobNameCalculator.Calculate(args);
        var client        = GetMinioClient(args);
        var containerName = GetContainerName(args);

        return(await BlobExistsAsync(client, containerName, blobName));
    }
Beispiel #3
0
    public override async Task <bool> DeleteAsync(BlobProviderDeleteArgs args)
    {
        var blobName      = MinioBlobNameCalculator.Calculate(args);
        var client        = GetMinioClient(args);
        var containerName = GetContainerName(args);

        if (await BlobExistsAsync(client, containerName, blobName))
        {
            await client.RemoveObjectAsync(containerName, blobName);

            return(true);
        }

        return(false);
    }
Beispiel #4
0
    public override async Task SaveAsync(BlobProviderSaveArgs args)
    {
        var blobName      = MinioBlobNameCalculator.Calculate(args);
        var configuration = args.Configuration.GetMinioConfiguration();
        var client        = GetMinioClient(args);
        var containerName = GetContainerName(args);

        if (!args.OverrideExisting && await BlobExistsAsync(client, containerName, blobName))
        {
            throw new BlobAlreadyExistsException($"Saving BLOB '{args.BlobName}' 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, blobName, args.BlobStream, args.BlobStream.Length);
    }
Beispiel #5
0
    public override async Task <Stream> GetOrNullAsync(BlobProviderGetArgs args)
    {
        var blobName      = MinioBlobNameCalculator.Calculate(args);
        var client        = GetMinioClient(args);
        var containerName = GetContainerName(args);

        if (!await BlobExistsAsync(client, containerName, blobName))
        {
            return(null);
        }

        Stream blobStream = null;
        await client.GetObjectAsync(containerName, blobName, (stream) =>
        {
            blobStream = stream;
        });

        return(await TryCopyToMemoryStreamAsync(blobStream, args.CancellationToken));
    }