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))); }
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)); }
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)); }
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); }