Esempio n. 1
0
    public override Task <bool> ExistsAsync(BlobProviderExistsArgs args)
    {
        var containerName = GetContainerName(args);
        var blobName      = AliyunBlobNameCalculator.Calculate(args);
        var ossClient     = GetOssClient(args.Configuration);

        return(Task.FromResult(BlobExists(ossClient, containerName, blobName)));
    }
Esempio n. 2
0
    public override Task <bool> DeleteAsync(BlobProviderDeleteArgs args)
    {
        var containerName = GetContainerName(args);
        var blobName      = AliyunBlobNameCalculator.Calculate(args);
        var ossClient     = GetOssClient(args.Configuration);

        if (!BlobExists(ossClient, containerName, blobName))
        {
            return(Task.FromResult(false));
        }
        ossClient.DeleteObject(containerName, blobName);
        return(Task.FromResult(true));
    }
Esempio n. 3
0
    public override async Task <Stream> GetOrNullAsync(BlobProviderGetArgs args)
    {
        var containerName = GetContainerName(args);
        var blobName      = AliyunBlobNameCalculator.Calculate(args);
        var ossClient     = GetOssClient(args.Configuration);

        if (!BlobExists(ossClient, containerName, blobName))
        {
            return(null);
        }
        var result = ossClient.GetObject(containerName, blobName);

        return(await TryCopyToMemoryStreamAsync(result.Content, args.CancellationToken));
    }
Esempio n. 4
0
    public override Task SaveAsync(BlobProviderSaveArgs args)
    {
        var containerName = GetContainerName(args);
        var blobName      = AliyunBlobNameCalculator.Calculate(args);
        var aliyunConfig  = args.Configuration.GetAliyunConfiguration();
        var ossClient     = GetOssClient(aliyunConfig);

        if (!args.OverrideExisting && BlobExists(ossClient, 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 (aliyunConfig.CreateContainerIfNotExists)
        {
            if (!ossClient.DoesBucketExist(containerName))
            {
                ossClient.CreateBucket(containerName);
            }
        }
        ossClient.PutObject(containerName, blobName, args.BlobStream);
        return(Task.CompletedTask);
    }